I have the following chart:
<cht:Chart ...>
<cht:Chart.Series>
<cht:LineSeries Name="LineSeries" Title="a"
DependentValueBinding="{Binding Path=Value}"
IndependentValueBinding="{Binding Path=Key}"
ItemsSource="{Binding Path=SourceCollection}"
IsSelectionEnabled="True"
DataPointStyle="{DynamicResource SmallPointStyle}">
</cht:LineSeries>
</cht:Chart.Series>
</cht:Chart>
And the DataPointStyle:
<Style TargetType="cht:LineDataPoint">
<Setter Property="Width" Value="2" />
<Setter Property="Height" Value="2" />
<Setter Property="DependentValueStringFormat" Value="{}{0:0.00}"/>
</Style>
<Style x:Key="SmallPointStyle" TargetType="cht:LineDataPoint" BasedOn="{StaticResource {x:Type cht:LineDataPoint}}">
<Setter Property="BorderBrush" Value="Orange"/>
<Setter Property="Background" Value="Orange"/>
</Style>
The source collection is a list of KeyValuePair.
The application works fine.
I encountered a problem because i want to use a collection of KeyValuePair> where doubleA is the data extracted and the doubleB is a normalised value of doubleA, based on a range. so i need to change the LineSeries to be:
<cht:Chart ...>
<cht:Chart.Series>
<cht:LineSeries Name="LineSeries" Title="a"
DependentValueBinding="{Binding Path=Value.Value}"
IndependentValueBinding="{Binding Path=Key}"
ItemsSource="{Binding Path=SourceCollection}"
IsSelectionEnabled="True"
DataPointStyle="{DynamicResource SmallPointStyle}">
</cht:LineSeries>
</cht:Chart.Series>
</cht:Chart>
It works as i expected, but i need to show in the tooltip the real value (Value.Key), not the DependentValue. is there anyway to accomplish that?
See this blog post for one possible solution.
You find the LineSeries data point style that you have to override here.
However, keep in mind that when you override the template you will not get any random colors anymore.
Good luck!
Related
I have a main list which is a ribbon group.
Inside each ribbon group there is another list called subfuctions for ribbon buttons.
<DataTemplate x:Key="buttonTempl">
<RibbonButton IsEnabled="{Binding IsEnabled}" Label="{Binding Path=SubFunctionName}" Command="{Binding SubFunctionCommand}" LargeImageSource="{Binding LargeButtonImage}" SmallImageSource="{Binding SmallButtonImage}"/>
</DataTemplate>
<RibbonGroupSizeDefinitionBaseCollection x:Key="groupSize">
<RibbonGroupSizeDefinition IsCollapsed="False" />
</RibbonGroupSizeDefinitionBaseCollection>
<Style TargetType="RibbonGroup" x:Key="groupStyle">
<Setter Property="GroupSizeDefinitions" Value="{StaticResource groupSize}"/>
<Setter Property="Header" Value="{Binding DisplayName}"/>
<Setter Property="ItemsSource" Value="{Binding SubFunctions}"/>
<Setter Property="ItemTemplate" Value="{StaticResource buttonTempl}"/>
<Setter Property="SmallImageSource" Value="{Binding RibbonGroupSmallImageSource}"/>
<Setter Property="Margin" Value="0"/>
</Style>
<Style TargetType="RibbonTab" x:Key="tabStyle">
<Setter Property="Header" Value="Pump"/>
<Setter Property="ItemsSource" Value="{Binding MainFunctions}"/>
<Setter Property="ItemContainerStyle" Value="{StaticResource groupStyle}"/>
</Style>
Hence groupSizedefinition is working if I use ribbongroup as separate as below:
<RibbonGroup Header="Selection" Name="SelectionMenu" GroupSizeDefinitions="{StaticResource groupSize}">
but not working with the above code that is with template.
What could be done to work groupsizedefinition with ribbongroup defined as style?
This is not really an answer, but it is too much for a comment.
I tried to reproduce this problem and observed the following effects using the "Live Visual Tree" and the "Live Property Explorer" windows in the debugger.
Specifying the GroupSizeDefinitions explicitly
<RibbonGroup Style="{StaticResource groupStyle}" GroupSizeDefinitions="{StaticResource groupSize}" />
the GroupSizeDefinitions in the style is crossed out, and the local definition is used
Specifying the GroupSizeDefinitions in the styls
<RibbonGroup Style="{StaticResource groupStyle}"/>
The Live property explorer shows a Local definition, which in my opinion is not present, is also crossed out.
The GroupSizeDefinitions which are actually being used are under the heading Coercion.
I'm afraid that I can't explain that, but maybe somebody else can.
here i want to give alternate color white and grey to grid row . i hv done many try but i can not do styling of grid .the code is here
<Style TargetType="{x:Type wpftoolkit:DataGrid}">
<Setter Property="Margin" Value="0" />
<Setter Property="BorderBrush" Value="#A6A6A6" />
<Setter Property="BorderThickness" Value="0,1,0,0"/>
<Setter Property="Background" Value="{StaticResource GridBgBrush}" />
<Setter Property="RowBackground" Value="White" />
<Setter Property="AlternatingRowBackground" Value="#FFF3F6FA" />
<Setter Property="GridLinesVisibility" Value="Horizontal" />
<Setter Property="HorizontalGridLinesBrush" Value="Transparent" />
<Setter Property="RowHeaderWidth" Value="0" />
</Style>
here StaticResource GridBgBrush define earlier on this file as`
plz give proper solution .thanks in advance.
Make sure that your style is either defined within the resources section of your XAML file (after your GridBgBrush, so that it can reference it), or in a ResourceDictionary in your App somewhere making it accessible from anywhere. Without seeing more, I can't tell you where your problem is coming from. That is the correct way to define your style and I have several examples of this working as expected if you're interested in seeing them.
Another thing to note in case you didn't know, is that DataGrid (along with DatePicker) was introduced into WPF v4.0. This makes the WPF Toolkit (at least for the purposes of the DataGrid) unnecessary if you can target that version. After saying that, I suppose there's the slight chance that if you weren't aware you were using one and then styling the other, your style wouldn't work.
<XmlDataProvider x:Key="myData" Source="Data.xml" IsAsynchronous="True" />
<Style TargetType="{x:Type DataGrid}" x:Key="myStyle">
<Setter Property="AlternatingRowBackground" Value="Red"/>
</Style>
<Grid>
<DataGrid ItemsSource="{Binding Source={StaticResource myData}, XPath=persons/person}" AutoGenerateColumns="False" Style="{StaticResource myStyle}">
<DataGrid.Columns>
<DataGridTemplateColumn>
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<TextBlock Text="{Binding XPath=firstname}" />
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>
<DataGridTemplateColumn>
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<TextBlock Text="{Binding XPath=lastname}" />
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>
</DataGrid.Columns>
</DataGrid>
</Grid>
You need to set AlternationCount property too.
I would like to take the xaml I currently have for a ComboBox (below), and condense it into something like the Style also shown below. I think this should work, but I have a 'Type'ing issue and not sure how to resolve it
"Cannot resolve the Style Property 'Margin'. Verify that the owning type is the Style's TargetType, or use Class.Property syntax to specify the Property.)
As I look at the existing ComboBoxStyle (also below) that I'm looking to base this new style off of, I see that I hadn't used x:Type, but it does seem to work.
Is there any reason this new style shouldn't work? What must I change?
Cheers,
Berryl
combo box, as is, working):
<ComboBox
x:Name="cboDepartmentFilter" Style="{StaticResource ComboBoxStyle}"
Margin="{StaticResource FliterPanelItem_Margin}" Width="{StaticResource FilterPanelItem_Width}"
ItemsSource="{Binding Path=DepartmentFilterControl.Choices}"
ToolTip="{Binding DepartmentFilterControlData.ToolTipTitle}"
/>
what I want:
<ComboBox Style="{StaticResource FilterPanelComboBoxStyle}" DataContext="{Binding DepartmentFilterControl}" />
<!- in some resource file ->
<Style x:Key="FilterPanelComboBoxStyle" BasedOn="{StaticResource ComboBoxStyle}">
<Setter Property="Margin" Value="{StaticResource FliterPanelItem_Margin}" />
<Setter Property="Width" Value="{StaticResource FilterPanelItem_Width}" />
<Setter Property="ItemsSource" Value="{Binding Choices}" />
<Setter Property="ToolTip" Value="{Binding ToolTipTitle}" />
</Style>
<!--
This style defines a common margin for items in a filter panel.
-->
150
existing ComboBoxStyle:
<!-- ComboBox Style -->
<Style x:Key="ComboBoxStyle" TargetType="ComboBox">
<Setter Property="Background" Value="{StaticResource headerBrush}" />
...
<Setter Property="Template">
<Setter.Value>
...
</Setter.Value>
</Setter>
<Setter Property="ItemContainerStyle" Value="{StaticResource ComboBoxItemStyle}" />
<Setter Property="IsSynchronizedWithCurrentItem" Value="True" />
</Style>
You still need to specify the TargetType in the derived style. (Or you prefix the properties with "ComboBox.")
I use an attached behavior that allows a DoubleClick event to be wired to a command in a view model, as in the binding below:
<ListBox Style="{StaticResource MasterListBoxStyle}"
b:SelectionBehavior.DoubleClickCommand="{Binding EditCommand}"
>
I need multiple list boxes for a presentation, all of which will need a DoubleClick wired to an EditCommand.
Can I push this behavior into my MasterListBoxStyle? How?
Cheers,
Berryl
<Style x:Key="MasterListBoxStyle" TargetType="ListBox">
<Setter Property="ItemsSource" Value="{Binding MasterVm.AllDetailVms}" />
<Setter Property="ItemContainerStyle" Value="{StaticResource MasterListingRowStyle}" />
<Setter Property="IsSynchronizedWithCurrentItem" Value="True" />
<Setter Property="AlternationCount" Value="2" />
</Style>
You should be able to add a simple Setter like so in WPF:
<Setter Property="b:SelectionBehavior.DoubleClickCommand" Value="{Binding EditCommand}" />
Assuming the b xmlns is defined in the XAML file that contains your Style.
This won't work in Silverlight though, since Bindings are not supported in Setters. This is something Microsoft is fixing in Silverlight 5.
I have a textbox that has the following simple XAML (not necessary to read it - just have it for reference):
<TextBox Name="m_ctrlUserDeviceType" Style="{StaticResource textStyleTextBox}" Text="{Binding Source={x:Static api:MySettings.Instance}, Path=UserDeviceType, ValidatesOnExceptions=true, NotifyOnValidationError=true}" Validation.Error="TextBox_Error" MinHeight="25" Margin="4" VerticalAlignment="Top" MaxLength="23" VerticalContentAlignment="Center" HorizontalAlignment="Left" MinWidth="100"></TextBox>
For completeness, the style textStyleTextBox looks like this (again, not necessary to read to answer question):
<Style x:Key="textStyleTextBox" TargetType="TextBox">
<Setter Property="Foreground" Value="#333333" />
<Setter Property="VerticalAlignment" Value="Top" />
<Setter Property="MinHeight" Value="2" />
<Setter Property="MinWidth" Value="100" />
<Setter Property="Margin" Value="4" />
<Setter Property="MaxLength" Value="23" />
<Setter Property="VerticalContentAlignment" Value="Center" />
<Setter Property="HorizontalAlignment" Value="Left" />
<!-- <Setter Property="Binding Source" Value="{x:Static api:MySettings.Instance}"/>
<Setter Property="Binding ValidatesOnExceptions" Value="true" />
<Setter Property="Binding NotifyOnValidationError" Value="true" /> -->
<Style.Triggers>
<Trigger Property="Validation.HasError" Value="true">
<Setter Property="ToolTip" Value="{Binding RelativeSource={RelativeSource Self},
Path=(Validation.Errors)[0].ErrorContent}" />
</Trigger>
</Style.Triggers>
</Style>
I have a lot of the stuff (MiHeight, Margin, etc.)in the style because I have a lot of these textboxes and they're almost exactly the same. In fact, there's a lot more in common than just the style. The details of the binding to the class MySettings are almost the same. The only difference is which particular property the textbox is binding too. Additionally, I always user TextBox_Error for Validation.Error.
Is there a way to put the binding info in Style or Data Template so I don't have to keep typing it for each textbox?
I would need to be able to assign an individual property (Path) for each textbox, and I suppose I still need the ability to not use any of it for some particular textbox added in the future (that has nothing to do with databinding to MySettings).
Is there a way to put the TextBox_Error part inside of style or DataTemplate? Using Setter Property did not seem to work for me.
I keep mentioning Data Template as I think the answer might have something to do with that based on reading Pro Silverlight 2 in C# 2008. However, I wasn't able to figure it out. I also tried adding stuff to "Style" as you can see from the commented out stuff in that section.
Thanks,
Dave
I dont think that there is a way to do what you are asking. However, I do think that you could go about it a different way.
What I would look into, is creating a custom control that extends TextBox, then create some dependency properties that, when the control is initialised, setup the bindings and error validation.
This way you can use your custom textbox all over your app and control every property, and even style them the same (just change the target type of your style)
HTH