A have a ListBox of items, every ListBoxItem contains an icon in the form of a Path object, like so:
<ListBox.ItemTemplate>
<DataTemplate>
<Grid ...>
...
<Path Margin="4" Style="{StaticResource ErrorIconPath}"
Stretch="Uniform" Width="26" Height="26"
RenderTransformOrigin="0.5,0.5" Grid.Column="1" Grid.Row="1"
UseLayoutRounding="False"
HorizontalAlignment="Center" VerticalAlignment="Center" />
</Grid>
</DataTemplate>
</ListBox.ItemTemplate>
The Path's style is contained in Appl.xaml (Application.Resources section) and is the following:
<Style x:Key="ErrorIconPath" TargetType="Path">
<Setter Property="Data" Value="F1M874.094,289.369L854.3,254.63C854.028,254.151 853.515,253.856 852.958,253.856 852.403,253.856 851.89,254.151 851.617,254.63L831.824,289.369C831.555,289.84 831.559,290.416 831.835,290.883 832.111,291.348 832.618,291.634 833.165,291.634L872.752,291.634C873.299,291.634 873.805,291.348 874.081,290.883 874.357,290.416 874.361,289.84 874.094,289.369 M855.653,287.189L850.264,287.189 850.264,282.745 855.653,282.745 855.653,287.189z M855.653,279.41L850.264,279.41 850.264,266.077 855.653,266.077 855.653,279.41z" />
</Style>
The trouble is that only the first item in the ListBox binds the Data property as expected, the other ones don't bind it at all (hence they appear as blank space, but match the size of the Path). Also when I use the style anywhere else (i.e. outside the ListBox), only the first instance that occurs will bind.
The weird thing is that if I define for example the Fill property in the Style instead of inline, it works just fine and doesn't exibit the same problems as the Path property.
My guess is that is has something to do with Data not being a primitive type, but I haven't found any fixes.
EDIT: Interestingly, when I bind the Data property directly to System.String resource, it works. I would still like to be able to define this property via a Style though.
EDIT 2: I've just came across the same issue in WPF, when setting Path to a Content of a Button via a Style that is used across more buttons. The path shows up in just one buttons, the others are blank.
Path.Fill is a DependencyProperty, while Path.Data isn't. Instead do:
<DataTemplate>
<Grid ...>
...
<ContentPresenter Content="{StaticResource MyPath}"/>
</Grid>
</DataTemplate>
ContentPresenter.Content is a DependencyProperty so this should work:
<Path x:Key="MyPath" Margin="4" Style="{StaticResource ErrorIconPath}"
Stretch="Uniform" Width="26" Height="26" VerticalAlignment="Center"
RenderTransformOrigin="0.5,0.5" Grid.Column="1" Grid.Row="1"
UseLayoutRounding="False" HorizontalAlignment="Center"
Data="F1M874.094,289.369L854.3,254.63C854.028,254.151 853.515,253.856 852.958,253.856 852.403,253.856 851.89,254.151 851.617,254.63L831.824,289.369C831.555,289.84 831.559,290.416 831.835,290.883 832.111,291.348 832.618,291.634 833.165,291.634L872.752,291.634C873.299,291.634 873.805,291.348 874.081,290.883 874.357,290.416 874.361,289.84 874.094,289.369 M855.653,287.189L850.264,287.189 850.264,282.745 855.653,282.745 855.653,287.189z M855.653,279.41L850.264,279.41 850.264,266.077 855.653,266.077 855.653,279.41z"/>
I am guessing that Geometry cannot be shared. Have you tried setting the x:Shared= "false" to:
<Style x:Key="ErrorIconPath" TargetType="Path">
I've experienced the same behavior in Silverlight and asked a similar question here on StackOverflow.com
( https://stackoverflow.com/q/13426198/1796930), but as I'm writing this, it's been 1 month and I've yet to get even a single answer.
However, as you mentioned in your first edit, I too was able to perform a workaround by creating a resource with my geometry data as a string and then binding the Data property of the Path objects to the string resource resource.
I also had to create two instances of the Path objects that were identical other than each one using a different resource (i.e. two different icons) and then binding the visibility of each to a property in my ViewModel to display the appropriate one.
I am very sure that you did not forgot the stroke here in Path style
<Setter Property="Stroke" Value="Red"/>
I have tested you code on my machine , it worked fine if above line added in style
My first tought was your Path would be broken or not valid. But then I saw you are using the Syncfusion Metro Studio. I tried it with exactly the same code you have and it worked very well. In a Data Template of 5 Items or as a single Path Item.
Have you tried to set the Fill statically to Red or something?
Also maybe try this for the Style definition
<Style x:Key="ErrorIconPath" TargetType="{x:Type Path}">
Third suggestion would be to move the style definition from the App to your Page or even to your Control itself.
To be sure there will be no default styles applied, try
OverridesDefaultStyle="True"
Hope this helps :)
I am developing a Silverlight 4 out of browser application using a standard ComboBox and I need to press the tab key twice to move over the control. The other controls (TextBox, RadioButton etc) in the data entry form are all behaving normally, i.e. only a single tab is required.
I created a simple sample application and found that the ComboBox was behaving correctly so there is something special about my real application that is causing the problem. I suspect the problem is due to the fact that I am using the AccentColor Theme. I've had a number of problems with these themes and have come to realise that they should be considered as samples of what is possible. Their quality is not good enough for use in a production application as this Introducing the new Silverlight 4 themes blog post suggests.
I am asking this question so that I can answer it myself to capture the solution for future reference.
The AccentColor Theme creates an implicit Style for a ComboBox which includes setting the Template property. This template uses a ToggleButton with a custom style that wraps the ContentPresenter inside a ContentControl for some reason (styling?) and by default the IsTabStop property is true. Explicitly setting this property to false restores the intuitive behaviour of a single tab to move over the control.
<ContentControl VerticalAlignment="Center" IsTabStop="False">
<ContentControl.Foreground>
<SolidColorBrush x:Name="ContentPresenterWrapperColor" Color="{StaticResource BaseColor1}" />
</ContentControl.Foreground>
<ContentPresenter x:Name="contentPresenter" ContentTemplate="{TemplateBinding ContentTemplate}" Content="{TemplateBinding Content}" HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" Margin="{TemplateBinding Padding}" VerticalAlignment="{TemplateBinding VerticalContentAlignment}"/>
</ContentControl>
The standard ComboBox template does not include this ContentControl which explains the difference in behaviour. I am not familiar enough with the AccentColor theme to know if it would be better to remove the ContentControl altogether or if it is required for the custom visual styling.
FYI Silverlight Spy was a great help in tracking down the problem in the behaviour, even if it is a bit pricey imho :-)
My project currently has a PieChart with a legend. Due to size restrictions I was asked to make a modification where if you hover over the name in the legend, it would display the full name (in the event that it was partially cut off). This revealed to me the issue that if you want to make a minor functional change in a Telerik control you will have to develop a complete style for it.
I feel like there is no easy answer for this, so I figured I'd ask and see if a smartypants figured something clever out. We use lots of Telerik control so if I could take control of them with something like that without having to completely redo them, it would give me a huge amount of control over my interface's more advanced features.
As a note, we are currently using version 2011.1.315.1040, I tried updating to the newest version today but it seems that they altered a control we use often, so I'd prefer to not have to update unless there is really a benefit since there will be a lot of reworking required.
An example style on telerik's website for what I was attempting to modify can be found here
Here is the piechart we are using as an example.
<telerik:RadChart Name="CoreChart"
VerticalAlignment="Top"
PaletteBrushesUseSolidColors="True"
PaletteBrushesRepeat="True"
BorderBrush="Transparent"
Background="Transparent"
BorderThickness="0">
<telerik:RadChart.PaletteBrushes>
<SolidColorBrush Color="#93d2ff" />
<SolidColorBrush Color="#ce0013" />
</telerik:RadChart.PaletteBrushes>
<telerik:RadChart.SeriesMappings>
<telerik:SeriesMapping>
<telerik:ItemMapping FieldName="Value" DataPointMember="YValue" />
<telerik:ItemMapping FieldName="Title" DataPointMember="LegendLabel" />
<telerik:SeriesMapping.SeriesDefinition>
<telerik:PieSeriesDefinition ShowItemLabels="False"
ShowItemToolTips="True"
ItemToolTipFormat="{Binding ToolTipFormat}">
<telerik:PieSeriesDefinition.InteractivitySettings>
<telerik:InteractivitySettings SelectionMode="Single"
SelectionScope="Item" HoverScope="None"/>
</telerik:PieSeriesDefinition.InteractivitySettings>
</telerik:PieSeriesDefinition>
</telerik:SeriesMapping.SeriesDefinition>
</telerik:SeriesMapping>
</telerik:RadChart.SeriesMappings>
<telerik:RadChart.DefaultView>
<telerik:ChartDefaultView ChartLegendPosition="Right" >
<telerik:ChartDefaultView.ChartArea>
<telerik:ChartArea HorizontalAlignment="Left" LegendName="ChartLegend"
BorderBrush="Transparent" EnableAnimations="True"
Background="Transparent" >
<telerik:ChartArea.AxisX>
<telerik:AxisX AxisLabelsVisibility="Collapsed" />
</telerik:ChartArea.AxisX>
</telerik:ChartArea>
</telerik:ChartDefaultView.ChartArea>
<telerik:ChartDefaultView.ChartLegend >
<telerik:ChartLegend x:Name="ChartLegend" Style="{StaticResource
ChartLegendStyle}" LegendItemMarkerShape="Square" Header=""
BorderThickness="0" Background="Transparent"
BorderBrush="Transparent" Width="150" />
</telerik:ChartDefaultView.ChartLegend>
</telerik:ChartDefaultView>
</telerik:RadChart.DefaultView>
</telerik:RadChart>
The way the control is built, you'll have to have a style with a ControlTemplate for the ChartLegendItem. In the link for Telerik's documentation there is a TextBlock named "PART_TextBlock". Change it to look like this:
<TextBlock x:Name="PART_TextBlock"
Grid.Column="1"
Foreground="{TemplateBinding Foreground}"
Margin="{TemplateBinding Margin}"
Padding="{TemplateBinding Padding}"
Text="{TemplateBinding Label}"
TextTrimming="CharacterEllipsis"
ToolTipService.ToolTip="{Binding Text, RelativeSource={RelativeSource Self}}" />
In the instance of ChartLegend
<telerik:ChartLegend x:Name="ChartLegend"
.....
LegendItemStyle="{StaticResource MyLegendItemStyle}" />
This will save you the need for a style of a Legend.
Another tip, to get all default styles of Telerik's controls, go to c:\Program Files (x86)\Telerik\RadControls for Silverlight Q1 2011\Themes - there's a solution there that has all the styles of all the themes.
I have many FrameworkElements (TextBlock, CheckBox, ListBox..) and I would like to make something allowing me to show a small number besides every one control.
Some text ³
I came with the idea to write a MarkupExtension, where I could write that number like this:
..
<TextBlock Text="Some Text" SomeExtension="3" />
..
and then to add it somehow to the template of the Control.
But I'm sure, you guys have better solution for this problem ;)
One way to go with it would be create a Attached Property. Upon setting it on a control, a custom Adorner would be added for that control showing specified number.
Use the tag property to provide the number you want and inside the custom template databind to the property
<TextBlock Text="Some Text" Tag="3" />
and inside the controltemplate
<TextBlock Text="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=Tag}"/>
<Border BorderBrush="#C4C8CC" BorderThickness="0,0,0,1">
<TextBlock x:Name="SectionTitle" FontFamily="Trebuchet MS" FontSize="14" FontWeight="Bold" Foreground="#3D3D3D" />
</Border>
I have to use the same above format at many places in a single xaml page, so for this i created a usercontrol and defined the above code inside it.
So my question is,
What i am doing is it right approach?
Will it make the page to load slower then the above code used as it is without defining it in a new user control?
I doubt you would notice a difference. However a lighter and more flexiable approach would be to use a Templated Control instead of a UserControl. Its a little more technical but results in a tighter implementation.
How many is "many" anyhow?