Does anybody know how to turn off the datapoints for a noraml LineSeries in a WPFToolkit chart? I find them to be very annoying, and not useful to my purposes, but I can't find a simple property or anything like that on the class itself.
You want to hide them?
It is possible if to set the empty ControlTemplate to the Template property.
Here is the example:
<Window.Resources>
<Style x:Key="InvisibleDataPoint" TargetType="{x:Type charting:DataPoint}">
<Setter Property="Background" Value="Blue"/>
<Setter Property="Template" Value="{x:Null}"/>
</Style>
</Window.Resources>
<Grid>
<charting:Chart>
<charting:LineSeries ItemsSource="{Binding ChartItems}" IndependentValuePath="XValue" DependentValuePath="YValue"
DataPointStyle="{StaticResource InvisibleDataPoint}"/>
</charting:Chart>
</Grid>
And although the points are invisible, you can set other properties, like Background and change the look of chart.
Related
After lots of research, I stumbled across a relatively simple way to target just specific parts of the control style without using the entire control template. It's partially successful, but I need a little help getting all the way to the end.
Specifically, I am trying to override the Thumb button color of the scrollbar in the dropdown of a ComboBox. The cool technique I came across is the following, which utilizes nested Style.Resources to access the lower objects...
<Style x:Key="MyComboBoxStyle" TargetType="{x:Type ComboBox}">
<Style.Resources>
<Style TargetType="ScrollViewer">
<Style.Resources>
<Style TargetType="ScrollBar">
<Setter Property="Background" Value="LightGreen" />
<Style.Resources>
<Style TargetType="Track">
<Setter Property="Cursor" Value="Cross" />
<Style.Resources>
<Style TargetType="Thumb">
<Setter Property="Background" Value="Red"/>
<Setter Property="Cursor" Value="Hand" />
</Style>
</Style.Resources>
</Style>
<Style TargetType="RepeatButton">
<Setter Property="Background" Value="Red"/>
<Setter Property="Cursor" Value="Hand" />
</Style>
</Style.Resources>
</Style>
</Style.Resources>
</Style>
</Style.Resources>
<!--- rest of ComboBox style definition follows... -->
By sequentially drilling down into the complex control style tree, using nested Style.Resources, I am able to target specific aspects of a control style, without needing the entire style definition.
The xaml code above successfully drills all the way down to the "Track"... I can change things like the margin, cursor, etc. of the Track. But, I just can't seem to get that last step to the Thumb. Also, I can't seem to access the Repeat buttons, which should be at the same level (in the object tree) as the Track.
Looking at the style template for ScrollBars seems to show that the object tree is ScrollBar->Track->Thumb... but I seem to be missing something?
Any ideas on how to get access to the Thumb color?
The default style for the ScrollBar sets the Style property of the Thumb explicitly in the Track:
<Track x:Name="PART_Track" ...>
...
<Track.Thumb>
<Thumb Style="{StaticResource ScrollBarThumbVertical}"/>
</Track.Thumb>
</Track>
This means that your implicit Thumb style won't be applied.
So you will have to define a custom complete ControlTemplate for the ScrollBar to be able to modify the style/template of the Thumb.
Alternatively, you may consider to look it up in the visual tree at runtime and set any of its properties programmatically.
Im currently working on a little Project, where i make use of the WPF Charting Toolkit.
now im a bit annoyed by these huge margin
<ch:Chart Grid.Row="1" x:Name="Chart">
<ch:Chart.LegendStyle>
<Style TargetType="{x:Type vt:Legend}">
<Setter Property="Width" Value="0"/>
<Setter Property="Height" Value="0"/>
</Style>
</ch:Chart.LegendStyle>
<ch:LineSeries ItemsSource="{Binding WeightChartData, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" DependentValuePath="Value" IndependentValuePath="Key" />
<ch:Chart.Axes>
<ch:LinearAxis Minimum="{Binding MinVal}" Maximum="{Binding MaxVal}" Orientation="Y"/>
</ch:Chart.Axes>
</ch:Chart>
this is the XAML from the chart.
is there any way i can make the Chart bigger
In order to make the margins more comfortable, you have to create a new style for the Chart. Easiest way is to copy the original Chart style completely and modify it to meet your needs.
The original style is available from GitHub. From that file you can find Style TargetType="charting:Chart", where the large margins are defined. For example:
<Setter Property="LegendStyle">
<Setter.Value>
<Style TargetType="datavis:Legend">
<Setter Property="Margin" Value="15,0,15,0" />
Alternatively, you can check the following SO post for a "bare minimum" chart style and to modify it for your needs: Change margin around plot area and title in WPF Toolkit chart
I have extended ListBox control and wanted to give it rounded corner so I have applied styles as below and it works fine:
<control:MultiSelectionListBox SelectionMode="Extended" ItemsSource="{Binding Offerables,Mode=TwoWay}"
SelectedItemsList="{Binding SelectedOfferables, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" DisplayMemberPath="Name"
Grid.Row="6" Grid.Column="0" MaxHeight="150">
<control:MultiSelectionListBox.Resources>
<Style TargetType="Border">
<Setter Property="CornerRadius" Value="5"></Setter>
</Style>
</control:MultiSelectionListBox.Resources>
</control:MultiSelectionListBox>
but I have too many Listboxes and I don't wanted to add style in each and every control individually.
I wanted to define this style in app.xaml and wanted to reuse that design by name like Style = "{StaticResource RoundedListBoxStyle}".
I have tried like below in app.xaml but with no luck
<Style TargetType="ListBox" x:Key="RoundedListBoxStyle">
<Setter Property="Border" Value="10"></Setter>
</Style>
The member Border is not recognized or is not accessible.
Please guide me what I am doing wrong here.
Finally I managed to do that as Bradley Uffner mentioned in the comment Border is not the property of the ListBox and we cannot use it in style like that. I used Style.Resource and mentioned Style for Border elements as below:
<Style TargetType="ListBox" x:Key="RoundedListBoxStyle">
<Style.Resources>
<Style TargetType="Border">
<Setter Property="CornerRadius" Value="5"></Setter>
</Style>
</Style.Resources>
</Style>
and it worked. :)
I'm trying to make a progress bar style that is re-usable.
So the idea here is very simple. I have a style already with target type ProgressBar, and it's just a spinny circle that fills as it goes from 0-100%. However, in order to make it re-usable and modular, I do not want to hard-code the text that goes along with it - it should be optional.
So I want to create another style that DOES include text "Downloading... X/Y MB". For this I take Value for X, Maximum for Y, and Tag for the unit. I want to include the same spinny circle thingy for the graphical part on the left. How can I do this? With BasedOn property, I think you can only set something already there to be different. What if I want to add additional elements (like textblocks in this case)?
If only text value differentiates then within style you can bind propertie's value to parent's property like Tag where at every single either style or element you adjust it to specific requirement.
<Window.Resources>
<Style x:Key="FirstButtonStyle" TargetType="Button">
<Setter Property="Content" Value="1"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="Button">
<ContentPresenter/>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
<Style x:Key="SecondButtonStyle" TargetType="Button" BasedOn="{StaticResource FirstButtonStyle}">
<Setter Property="Content" Value="2"/>
</Style>
</Window.Resources>
<StackPanel>
<Button Style="{StaticResource FirstButtonStyle}"/>
<Button Style="{StaticResource SecondButtonStyle}"/>
</StackPanel>
The outcome is 1 and 2. If your intent is to inject some UI element within style then there is no such an option, alas. Style needs to be rewritten once again.
How to make DataGrid transparent?
I'm trying to use Background of DataGrid itself, but this doesn't seem to work.
UPD I need only background and borders transparent, not everything! Text should be visible.
So, my solution... use both Background="Transparent" and RowBackground="Transparent"
Have you tried setting the Opacity property to 0.0 ?
A value of 0.0 makes the element
completely transparent
<DataGrid
Background="Transparent" RowBackground="Transparent">
</DataGrid>
Try this:
Background="Transparent" RowBackground="Transparent"
and
<DataGrid.ColumnHeaderStyle>
<Style TargetType="{x:Type DataGridColumnHeader}">
<Setter Property="Background" Value="Transparent" />
<Setter Property="FontWeight" Value="Bold" />
</Style>
</DataGrid.ColumnHeaderStyle>
<DataGrid.RowHeaderStyle>
<Style TargetType="{x:Type DataGridRowHeader}">
<Setter Property="Background" Value="Transparent" />
</Style>
</DataGrid.RowHeaderStyle>
It's an undocumentd feature but if you set the visability to Hidden it's the same as setting the element to transparent.
I'm not sure which background you are trying to change, but you can set any background by overriding the DataGrid's ControlTemplate. Your best bet is probably to copy the default DataGrid ControlTemplate from here and then modify the necessary background to match your needs.
When you inicialize datagrid put this tag GridLinesVisibility with argument None
For example:
<DataGrid GridLinesVisibility="None"/>