|
There's nothing wrong with your sample there. That works perfectly well, assuming that MyParent is accessible to SubText.
|
|
|
|
|
I've try it but no luck,
"MyParent" is a ListBox control, i have created a DataTemplate where SubText TextBlock is in and i've tried to bind the lisbox tooltip to the subtext text but failed Miserably.
|
|
|
|
|
Why not just bind the tooltip in MyParent to the same element you are binding to as SubText?
|
|
|
|
|
Hi You can create a custom control based on what control you are using as parent. If you are using ListBox it would be like below
public class CustomListBox : ListBox
{
public object ToolTip
{
get
{
return ToolTipService.GetToolTip(this);
}
}
}
You xaml will look like below
<local:CustomListBox ItemsSource="{Binding Path=CustomerList}"
ToolTipService.ToolTip="Your Tooltip"
x:Name="lstParent">
<local:CustomListBox.ItemTemplate>
<DataTemplate>
<TextBlock Text="{Binding Path=ToolTip, ElementName=lstParent}" />
</DataTemplate>
</local:CustomListBox.ItemTemplate>
</local:CustomListBox>
Let me know if it works.
http://www.exploresilverlight.com
Cheers!
Vinod
Vinod
|
|
|
|
|
I created a button class:
public class ImageTextButton : Button
{
public ImageSource NormalImageSource
{
get { return (ImageSource)GetValue(NormalImageSourceProperty); }
set { SetValue(NormalImageSourceProperty, value); }
}
public static readonly DependencyProperty NormalImageSourceProperty =
DependencyProperty.Register("NormalImageSource", typeof(ImageSource), typeof(ImageTextButton), new UIPropertyMetadata(null));
public ImageSource MouseOverImageSource
{
get { return (ImageSource)GetValue(MouseOverImageSourceProperty); }
set { SetValue(MouseOverImageSourceProperty, value); }
}
public static readonly DependencyProperty MouseOverImageSourceProperty =
DependencyProperty.Register("MouseOverImageSource", typeof(ImageSource), typeof(ImageTextButton), new UIPropertyMetadata(null));
public string Caption
{
get { return (string)GetValue(CaptionProperty); }
set { SetValue(CaptionProperty, value); }
}
public static readonly DependencyProperty CaptionProperty =
DependencyProperty.Register("Caption", typeof(string), typeof(ImageTextButton), new UIPropertyMetadata(null));
}
and I use it like this:
<controls:ImageTextButton Caption="Test"
NormalImageSource="Images/metro_save_disabled_48.png"
MouseOverImageSource="Images/metro_save_enabled_48.png"
Style="{StaticResource ImageTextButton}"
Grid.Row="1"
Grid.Column="1"/>
In the button's ControlTemplate I'm doing:
<ControlTemplate.Triggers>
<Trigger Property="Button.IsMouseOver" Value="True">
<Setter TargetName="ButtonImage" Property="Source" Value="{Binding RelativeSource={RelativeSource Self}, Path=MouseOverImageSource}" />
</Trigger>
</ControlTemplate.Triggers>
but it doesn't work. The image doesn't change. It disappears. Anyone know the right way to do this?
Thanks
If it's not broken, fix it until it is
|
|
|
|
|
Hi Kevin,
Just updating the source won't work. You have to update the Button Content.
for ex:
<button.content>
<stackpanel>
<image.source>
<BitmapImage UriSource="{Binding RelativeSource={RelativeSource Self}, Path=MouseOverImageSource}" />
<ControlTemplate.Triggers>
<Trigger Property="Button.IsMouseOver" Value="True">
<Setter TargetName="ButtonImage" Property="Content"/> <Setter.Value>
<StackPanel>
<Image>
<Image.Source>
<BitmapImage UriSource="{Binding RelativeSource={RelativeSource Self}, Path=MouseOverImageSource}" />
</Image.Source>
</Image>
</StackPanel>
<Setter.Value/>
</Trigger>
</ControlTemplate.Triggers>
I think this should work..
|
|
|
|
|
Thanks
virusattack wrote: <Button> < Button.Content> <stackpanel> < Image>
< Image.Source> < BitmapImage UriSource="{Binding
RelativeSource={RelativeSource Self}, Path=MouseOverImageSource}" />
< /Image.Source> < /Image>
< /Button.Content>
Where does this code go in the style?
If it's not broken, fix it until it is
|
|
|
|
|
Hi Kevin,
check in Trigger whether Button's IsMouseOver is true and set the property Content with the following values.
<ControlTemplate.Triggers>
<Trigger Property="Button.IsMouseOver" Value="True">
<Setter TargetName="ButtonImage" Property="Content"/> <Setter.Value>
<StackPanel>
<Image>
<Image.Source>
<BitmapImage UriSource="{Binding RelativeSource={RelativeSource Self}, Path=MouseOverImageSource}" />
</Image.Source>
</Image>
</StackPanel>
<Setter.Value/>
</Trigger>
</ControlTemplate.Triggers>
|
|
|
|
|
[UPDATE]
I set the TargetName property and it works now
<ControlTemplate.Triggers>
<Trigger Property="Button.IsMouseOver" Value="True">
<Setter TargetName="ButtonCaption" Property="FontWeight" Value="Bold"/>
<Setter TargetName="ButtonCaption" Property="Foreground" Value="#03AEDA"/>
<Setter TargetName="ButtonImage" Property="Source" Value="Images/metro_save_enabled_48.png" />
</Trigger>
</ControlTemplate.Triggers >
I created a button class that has Normal and MouseOver image properties. I want to change the image when the mouse is over the button.
public class ImageTextButton : Button
{
public ImageSource NormalImageSource
{
get { return (ImageSource)GetValue(NormalImageSourceProperty); }
set { SetValue(NormalImageSourceProperty, value); }
}
public static readonly DependencyProperty NormalImageSourceProperty =
DependencyProperty.Register("NormalImageSource", typeof(ImageSource), typeof(ImageTextButton), new UIPropertyMetadata(null));
public ImageSource MouseOverImageSource
{
get { return (ImageSource)GetValue(MouseOverImageSourceProperty); }
set { SetValue(MouseOverImageSourceProperty, value); }
}
public static readonly DependencyProperty MouseOverImageSourceProperty =
DependencyProperty.Register("MouseOverImageSource", typeof(ImageSource), typeof(ImageTextButton), new UIPropertyMetadata(null));
public string Caption
{
get { return (string)GetValue(CaptionProperty); }
set { SetValue(CaptionProperty, value); }
}
public static readonly DependencyProperty CaptionProperty =
DependencyProperty.Register("Caption", typeof(string), typeof(ImageTextButton), new UIPropertyMetadata(null));
}
Here's my button style:
<Window.Resources>
<Style TargetType="{x:Type controls:ImageTextButton}"
x:Key="ImageTextButton">
<Setter Property="Height" Value="55"/>
<Setter Property="Width" Value="135"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type controls:ImageTextButton}">
<Border BorderBrush="DarkGray"
BorderThickness="1"
CornerRadius="3">
<StackPanel Orientation="Horizontal"
HorizontalAlignment="Center">
<Image x:Name="ButtonImage"
Source="{TemplateBinding NormalImageSource}"
Height="48"
Width="48"
Margin="3"
HorizontalAlignment="Center"
VerticalAlignment="Center"
Stretch="Fill"/>
<TextBlock x:Name="ButtonCaption"
Text="{TemplateBinding Caption}"
Grid.Row="1"
HorizontalAlignment="Center"
VerticalAlignment="Center"
Foreground="DarkGray"
FontSize="18"/>
</StackPanel>
</Border>
<ControlTemplate.Triggers>
<Trigger Property="TextBlock.IsMouseOver" Value="True">
<Setter Property="TextBlock.FontWeight" Value="Bold"/>
<Setter Property="TextBlock.Foreground" Value="SteelBlue"/>
</Trigger>
<Trigger Property="Image.IsMouseOver" Value="True">
<Setter Property="Image.Source" Value="{Binding RelativeSource={RelativeSource Self}, Path=MouseOverImageSource}" />
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</Window.Resources>
and how I'm using it:
When I mouse over the button, the Caption's color stays gray, and the image doesn't change. Also, the caption only gets Bold when I mouse over the caption, nit the button.
Anyone see what's wrong?
Thanks
If it's not broken, fix it until it is
modified 2-Jul-12 17:42pm.
|
|
|
|
|
Ok, I don't understand this.
I created a button style:
<Style x:Key="MenuButtonStyle"
TargetType="Button"
BasedOn="{StaticResource ButtonStyle}">
</Style>
You can see that it's based on ButtonStyle, which is
<Style TargetType="{x:Type Button}"
x:Key="ButtonStyle"
BasedOn="{StaticResource BaseStyle}"/>
ButtonStyle is based off BaseStyle
<Style TargetType="{x:Type Control}"
x:Key="BaseStyle">
<Setter Property="FontFamily" Value="Segoe UI"/>
<Setter Property="FontSize" Value="12"/>
<Setter Property="FontWeight" Value="Bold"/>
<Setter Property="Foreground" Value="Gray"/>
</Style>
Everything works fine.
So, I'm trying to do the same with a textblock. The style...
<Style TargetType="{x:Type TextBlock}"
x:Key="TextBlockStyle"
BasedOn="{StaticResource BaseStyle}"/>
and it's usage:
<TextBlock Text="Hello"
Grid.Column="0"
Style="{StaticResource TextBlockStyle}"/>
The designer throws the exception "Can only base on a Style with target type that is base type 'TextBlock'."
What gives????
If it's not broken, fix it until it is
|
|
|
|
|
TextBlock doesn't inherit from "Control".
|
|
|
|
|
Well, that would do it, huh?
If it's not broken, fix it until it is
|
|
|
|
|
If you look at the hierarchy, Button [^] is based on Control , but TextBlock [^] is not, so TextBlockStyle cannot be based on a style that is above it in the hierarchy.
|
|
|
|
|
I want to create menu in my app that looks like Zune[^]
So I styled a button, and it looks fine. The question is, what's the best way to load this? Would you define each button on its own in XAML or use some kind of list or stackpanel that's bound to the VM?
I would like the menu(s) to be dynamic, so I will have to bind the Caption, the Visibility, and the Command would be bound to something like Button1Command, Button2Command, ect. Then in the code behind determine what to do based of the state of the app.
Also, when a button is clicked, it's FontWeight needs to be set to bold, and all other buttons to Normal. How would you do this?
Sugggestions?
Thanks
If it's not broken, fix it until it is
|
|
|
|
|
You create a single style in a central location. This is called the resource dictionary.
You then use this style in any buttons defined in any xaml.
It is not advisable to have this style copy pasted in every single xaml.
That would be a maintenance nightmare.
The Visual State Manager class[^] should help you setup a transition for the fontweight task.
You can also set up a simple animation for this task.
|
|
|
|
|
I am not aware of Zune, however, I think you can use a Menu control and set its source to a collection ObservableCollection<imenuitem> MenuItems.
interface IMenuItem {
string Caption;
Visibility MenuVisibility;
ICommand Command;}
Bind the above properties in the MenuItem's ItemTemplate or HiearchicalTemplate.
Apply DataTrigger on the MenuVisibility property to set visibility.
Also you can customize the default menuitem's template style and modify the template as per your requirement.
Please refer the below link which will give an idea on how to use the menu item template.
http://msdn.microsoft.com/en-us/library/ms752296%28v=vs.85%29[^]
http://msdn.microsoft.com/en-us/library/ms747082%28v=vs.85%29.aspx[^]
|
|
|
|
|
Hi,
What is the default font used in silverlight XAML page.
How can i use xaml default font in aspx pages?
Thankyou,
YPKI
|
|
|
|
|
I believe it is Portable UI, which uses Verdana for Western Characters.
|
|
|
|
|
Jeremy's answer is indeed validated by this article[^].
"The default value is "Portable User Interface", which is described in the "Supported Local Fonts" section of this topic. FontFamily can include a URI string that references a font file (and a family within the file, separated by a # character). This is for a case where rather than using fonts on the user system, you distribute the font file as part of your application's primary assembly."
|
|
|
|
|
Hi To All
I need to add the footer in DataGrid of Silverlight but i did not find any method to add the footer. the itemsource of datagrid set at run time so number of rows in datagrid may be changed every time.
Is any way to add the Footer in DataGrid?
Thanks
Sudhir
|
|
|
|
|
This link[^] might actually help you create a custom footer for your application.
|
|
|
|
|
Hi All,
I have drawn a closed path in a canvas that contains a multiscale image. So the closed path is drawn over the multiscaleimage. However, the multiscale image MouseMove and MouseWheel events do not work when the mouse pointer is over the closed path. The multiscale image mouse events only work in the image places outside the path. How to make the multiscale image mouse events work in the closed path?
Thanks in advance for your help,
Luis Nambiar
|
|
|
|
|
Setting the IsHitTestVisible property to false should do it.
|
|
|
|
|
Hi,
I'm busy with a Silverlight 5 project in which it's needed to upload PDF docs. A manager should be able to quickly preview these docs in the app. So all I need is to have a way to view the PDF contents in my Silverlight app. I have found a few solutions on the net, but almost all of them have a whole list of other features I will never use and as a result cost an arm an a leg.
So I thought the easiest way would be to convert the PDF pages into images as silverlight has no trouble displaying images. All I should need is a way to open the doc and then convert each page into an image. I'd like to be able to do this without a round trip to the server.
I know I can use an IFrame in a popup or something on top of the silverlight app, but right now that's my last resort.
Hope you can help,
Thanks
|
|
|
|
|
I'm trying to do this
<TextBlock Text="{Binding Path=Caption}"
Foreground="SlateBlue"
FontSize="14">
<TextBlock.Triggers>
<DataTrigger Binding="{Binding IsCurrentItem}" Value="True">
<Setter Property="FontWeight" Value="Bold"/>
</DataTrigger>
<DataTrigger Binding="{Binding IsCurrentItem}" Value="False">
<Setter Property="FontWeight" Value="Normal"/>
</DataTrigger>
</TextBlock.Triggers>
</TextBlock>
and it won't compile with
Cannot find the static member 'FontWeightProperty' on the type 'ContentPresenter'.
How can I set the font weight based on a bool in my data model?
If it's not broken, fix it until it is
|
|
|
|