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
Related
I want to change the border thickness and border brush of autosuggest box in UWP. But the change is not reflecting in the view.
Here is my code:
<Autosuggest Box border thickness="0.5" border brush="gray"/>
From AutoSuggestBox's template resources, you can see that this control contains a TextBox.
Modify the relevant properties.
<Page.Resources>
<Style x:Key="NewTextBoxStyle" TargetType="TextBox">
<Setter Property="BorderBrush" Value="Gray"/>
<Setter Property="BorderThickness" Value="0.5"/>
</Style>
<Style x:Key="NewStyle" TargetType="AutoSuggestBox">
<Setter Property="TextBoxStyle" Value="{StaticResource NewTextBoxStyle}" />
</Style>
</Page.Resources>
<Grid>
<AutoSuggestBox Style="{StaticResource NewStyle}"/>
</Grid>
If you need to modify other control properties in the future, you can first view the default style and composition structure of the control in generic.xaml, and then modify the property.
For design purposes, generic.xaml is available in the (Program
Files)\Windows Kits\10\DesignTime\CommonConfiguration\Neutral\UAP
\Generic folder from a Windows Software Development Kit
(SDK) installation.
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.
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 checked similar questions but I couldn't figure out the underlying logic.
I am trying to add CornerRadius to a TextBox in a WPF project.
Here's what I tried so far:
In App.xaml I created a Style that I intend to reuse:
<Style x:Key="TextBoxStyle" TargetType="{x:Type TextBox}">
<Setter Property="Height" Value="27"/>
<Setter Property="Padding" Value="5.5"/>
<Setter Property="BorderThickness" Value="0"/>
</Style>
Adding: <Setter Property="Border.CornerRadius" Value="5"/> didn't work. However, the following worked, but with side effects (all borders where rounded):
<Style TargetType="{x:Type Border}">
<Setter Property="CornerRadius" Value="5"/>
</Style>
I want to keep the styles separate and basically use them like this:
<TextBox x:Name="ExampleTb" Style="{StaticResource TextBoxStyle}"/>
Can you please help me/ point me in the right direction?
It is actually very simple to achieve this, just follow these steps:
Step 1. Add a textbox to your window, right click on your textbox and select "Edit Template \ Edit a Copy..."
This will take you to the control template designer.
Step 2. Check this picture:
https://postimg.org/image/9h5ng8p9t/
P.S. I find blend better suited to design controls.
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.