change point size in WPFToolkit - c#

i try to change point size in wpf toolkit
<charting:Chart Name="Charts" Margin="87,48,0,0" Grid.Column="1">
<charting:LineSeries Name="ChartOne" DependentValuePath="Y" IndependentValuePath="X" Title="График функции" AnimationSequence="FirstToLast"/>
<charting:Chart.Axes>
<charting:LinearAxis Orientation="Y" Title="Y" ShowGridLines="True" Minimum="0"/>
<charting:LinearAxis Orientation="X" Title="X" ShowGridLines="True" Minimum="0"/>
</charting:Chart.Axes>
<charting:LineSeries.DataPointStyle>
<Style TargetType="chartingToolkit:LineDataPoint">
<Setter Property="Width" Value="20"/>
<Setter Property="Height" Value="20"/>
</Style>
</charting:LineSeries.DataPointStyle>
</charting:Chart>
but i have an error "The attachable property 'DataPointStyle' was not found in type 'LineSeries'"
what am I doing wrong ?

This code works for me
<Window x:Class="WpfApplication1.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:charting="clr-namespace:System.Windows.Controls.DataVisualization.Charting;assembly=System.Windows.Controls.DataVisualization.Toolkit"
Title="MainWindow" Height="350" Width="525">
<Grid>
<charting:Chart Name="Charts" Margin="87,48,0,0" Grid.Column="1">
<charting:Chart.Axes>
<charting:LinearAxis Orientation="Y" Title="Y" ShowGridLines="True" Minimum="0"/>
<charting:LinearAxis Orientation="X" Title="X" ShowGridLines="True" Minimum="0"/>
</charting:Chart.Axes>
<charting:LineSeries Name="ChartOne" DependentValuePath="Y" IndependentValuePath="X"
Title="График функции" AnimationSequence="FirstToLast">
<charting:LineSeries.DataPointStyle>
<Style TargetType="{x:Type charting:LineDataPoint}">
<Setter Property="Width" Value="20"/>
<Setter Property="Height" Value="20"/>
</Style>
</charting:LineSeries.DataPointStyle>
</charting:LineSeries>
</charting:Chart>
</Grid>

Related

WPF global style for Window

I'm trying to add a global style (Font size and Font family) into my WPF application for Window I have, but no style Is applied to It, whatever I do. I think my problem Is that my startup Window Is not App.xaml, because I use App.xaml just to check If user has permission to run application. But right after that my desired Window opens, so StartupUri in my App.xaml Is set to that Window.
Here is my App.xaml:
<Application x:Class="MyApp.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:MyApp"
StartupUri="FirstWindowToShow.xaml">
<Application.Resources>
<!--Style that should be applied to all Windows-->
<Style x:Key="Win_style" TargetType="{x:Type Window}">
<Setter Property="FontFamily" Value="Comic Sans MS" />
<Setter Property="FontSize" Value="14" />
</Style>
<!--Style for all Pages - works fine-->
<Style x:Key="PageFont" TargetType="{x:Type Page}">
<Setter Property="FontFamily" Value="Comic Sans MS" />
<Setter Property="FontSize" Value="12" />
</Style>
</Application.Resources>
</Application>
And here is my FirstWindowToShow.xaml :
<Window x:Class="MyApp.FirstWindowToShow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:Priprava_Podatkov"
mc:Ignorable="d"
Title="Some title" Height="480" Width="800" Loaded="Window_Loaded" Background="#FFF9F9F9" OpacityMask="Black">
<Grid>
<Menu x:Name="G_Menu" HorizontalAlignment="Left" VerticalAlignment="Top" Height="20" Width="792">
<MenuItem x:Name="Menu_Program">
<MenuItem x:Name="Menu_V" Header="About" Click="Menu_V_Click"/>
<MenuItem x:Name="Menu_End" Header="Close" Click="Menu_End_Click"/>
</MenuItem>
<MenuItem Header="Department 1" Height="20" Width="148">
<MenuItem x:Name="Dept_1" Header="Custom controlling" Click="Dept_1_Click"/>
</MenuItem>
</Menu>
<Frame x:Name="Frame_s" HorizontalAlignment="Stretch" VerticalAlignment="Top" Width="772" NavigationUIVisibility="Hidden"/>
<StatusBar DockPanel.Dock="Bottom" Margin="0,386,0,0" VerticalAlignment="Bottom" Background="Transparent">
<StatusBarItem Width="73">
<Label Content="User:" FontWeight="Bold" Width="73"/>
</StatusBarItem>
<StatusBarItem>
<Label x:Name="LblU" Content="user" FontWeight="Light"/>
</StatusBarItem>
<StatusBarItem>
<Separator Style="{StaticResource {x:Static ToolBar.SeparatorStyleKey}}" Height="10" />
</StatusBarItem>
<StatusBarItem>
<Label Content="User permissions:" FontWeight="Bold" />
</StatusBarItem>
<StatusBarItem>
<Label x:Name="LblN" Content="Rights" FontWeight="Light"/>
</StatusBarItem>
<StatusBarItem >
<Label x:Name="Lbl_P" Content="Data exported..." >
<Label.Style>
<Style TargetType="{x:Type Label}">
<Style.Resources>
<Storyboard x:Key="flashAnimacija">
<DoubleAnimation Storyboard.TargetProperty="Opacity" From="1" To="0" AutoReverse="True" Duration="0:0:1.5" RepeatBehavior="Forever" />
</Storyboard>
</Style.Resources>
<Setter Property="Visibility" Value="Hidden" />
<Style.Triggers>
<DataTrigger Binding="{Binding ElementName= Progress_DoKonca, Path= IsVisible}" Value="True">
<Setter Property="Visibility" Value="Visible" />
<DataTrigger.EnterActions>
<BeginStoryboard Name="flash" Storyboard="{StaticResource flashAnimacija}" />
</DataTrigger.EnterActions>
<DataTrigger.ExitActions>
<StopStoryboard BeginStoryboardName="flash"/>
</DataTrigger.ExitActions>
</DataTrigger>
</Style.Triggers>
</Style>
</Label.Style>
</Label>
</StatusBarItem>
<StatusBarItem HorizontalAlignment="Right" Margin="-10,0,10,0">
<Grid>
<ProgressBar x:Name="Progress_TillEnd" Width="150" Height="20" />
<TextBlock x:Name="Progress_Txt" Text="{Binding ElementName=Progress_DoKonca, Path=Value, StringFormat={}{0:0}%}" HorizontalAlignment="Center" VerticalAlignment="Center" />
</Grid>
</StatusBarItem>
</StatusBar>
</Grid>
</Window>
I have been trying all sorts of things in code or XAML, like this or this, but still with no success. What am I doing wrong ?
This is what I've done in the past, so see if it works for you:
In your App.xaml, remove the x:Key from the Window style, so it becomes:
<!--Style that should be applied to all Windows-->
<Style TargetType="{x:Type Window}">
<Setter Property="FontFamily" Value="Comic Sans MS" />
<Setter Property="FontSize" Value="14" />
</Style>
Then in your App.xaml.cs (code-behind), override the OnStartup method and add this code:-
protected override void OnStartup(StartupEventArgs e)
{
base.OnStartup(e);
FrameworkElement.StyleProperty.OverrideMetadata(typeof(Window), new FrameworkPropertyMetadata
{
DefaultValue = FindResource(typeof(Window))
});
}
This will apply those styles in the App.xaml Window style (i.e. FontFamily and FontStyle) to all windows created by the application.
For the controls like Menu and StatusBar it is necessary to set the style explicitly like below:
<Style x:Key="BaseStyle" TargetType="{x:Type Control}">
<Setter Property="FontFamily" Value="Comic Sans MS" />
<Setter Property="FontSize" Value="13" />
</Style>
<Style TargetType="{x:Type StatusBar}" BasedOn="{StaticResource BaseStyle}" />
<Style TargetType="{x:Type Menu}" BasedOn="{StaticResource BaseStyle}" />
<Style TargetType="{x:Type local:Window1}" BasedOn="{StaticResource BaseStyle}" />
Why would a Style with an x:Key of "Win_style" be applied to all windows?
You could keep Win_style and define an implict Style per window type (e.g. FirstWindowToShow) that is based on Win_style:
<Application.Resources>
<!--Style that should be applied to all Windows-->
<Style x:Key="Win_style" TargetType="{x:Type Window}">
<Setter Property="FontFamily" Value="Comic Sans MS" />
<Setter Property="FontSize" Value="14" />
</Style>
<!-- implicit window styles, one for each window -->
<Style TargetType="{x:Type local:FirstWindowToShow}" BasedOn="{StaticResource Win_style}" />
<!--Style for all Pages - works fine-->
<Style x:Key="PageFont" TargetType="{x:Type Page}">
<Setter Property="FontFamily" Value="Comic Sans MS" />
<Setter Property="FontSize" Value="12" />
</Style>
</Application.Resources>

Style trigger property is not changing element's width in XAML

i am trying to trigger IsMouseOverproperty of an element and chnging the width in XAML and it's working but the problem is if i define the default or static width property in element's tag then this doesn't work. Why ?
Working code
<UserControl x:Class="IntelliVentory.UserControls.SideMenuBarControl"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:IntelliVentory.UserControls"
mc:Ignorable="d"
xmlns:materialDesign="http://materialdesigninxaml.net/winfx/xaml/themes"
xmlns:userControls="clr-namespace:IntelliVentory.UserControls"
TextElement.Foreground="{DynamicResource MaterialDesignBody}"
Background="{DynamicResource MaterialDesignPaper}"
TextElement.FontWeight="Medium"
TextElement.FontSize="14"
FontFamily="pack://application:,,,/MaterialDesignThemes.Wpf;component/Resources/Roboto/#Roboto"
d:DesignHeight="450" d:DesignWidth="800">
<Grid>
<ItemsControl Margin="50">
<ItemsControl.Resources>
<Style x:Key="ScaleStyle" TargetType="materialDesign:ColorZone">
<Style.Triggers>
<Trigger Property="IsMouseOver" Value="True">
<Setter Property="Width" Value="300" />
</Trigger>
</Style.Triggers>
</Style>
</ItemsControl.Resources>
<materialDesign:ColorZone Name="ColorZone1" Style="{StaticResource ScaleStyle}" Height="50"
Mode="PrimaryDark" Padding="16" CornerRadius="3"
materialDesign:ShadowAssist.ShadowDepth="Depth3" />
<materialDesign:ColorZone Margin="0 5 0 0" Name="ColorZone2" Style="{StaticResource ScaleStyle}"
Height="50" Mode="PrimaryDark" Padding="16" CornerRadius="3"
materialDesign:ShadowAssist.ShadowDepth="Depth3" />
<materialDesign:ColorZone Margin="0 5 0 0" Name="ColorZone3" Style="{StaticResource ScaleStyle}"
Height="50" Mode="PrimaryDark" Padding="16" CornerRadius="3"
materialDesign:ShadowAssist.ShadowDepth="Depth3" />
</ItemsControl>
</Grid>
but if now i add width="40" property then this trigger property wont work on first ColorZone Element Name="colorZone1" it won't work .
<materialDesign:ColorZone Name="ColorZone1" Style="{StaticResource ScaleStyle}" width="40" Height="50"
Mode="PrimaryDark" Padding="16" CornerRadius="3"
materialDesign:ShadowAssist.ShadowDepth="Depth3" />
You need to set the default width in the style.
<Style x:Key="ScaleStyle" TargetType="materialDesign:ColorZone">
<Style.Triggers>
<Trigger Property="IsMouseOver" Value="True">
<Setter Property="Width" Value="300" />
</Trigger>
</Style.Triggers>
<Style.Setters>
<Setter Property="Width" Value="40"/>
</Style.Setters>
</Style>

Oxyplot - Hiding Tick Mark Labels

I am trying to hide the first and last tick mark label on the x-axis. I've done it once via a style and style triggers, but that code has gone....somewhere. Here's what I'm working with.
<UserControl
x:Class="PentagearRT.Controls.Graph"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:oxy="http://oxyplot.org/wpf"
xmlns:local="clr-namespace:PentagearRT.Controls"
mc:Ignorable="d"
d:DesignHeight="500"
d:DesignWidth="800">
<Grid>
<oxy:Plot>
<oxy:Plot.Resources>
</oxy:Plot.Resources>
<oxy:Plot.Axes>
<oxy:LinearAxis Position="Left" Minimum="-5" Maximum="5" MajorStep="1"
MajorGridlineColor="AliceBlue" MajorGridlineThickness=".07" MajorGridlineStyle="Dot"/>
<oxy:LinearAxis Position="Bottom" Minimum="0" Maximum="360" MajorStep="45" StringFormat="0°"
MajorGridlineColor="AliceBlue" MajorGridlineThickness=".07" MajorGridlineStyle="Dot"/>
</oxy:Plot.Axes>
<oxy:LineSeries Background="Black"/>
</oxy:Plot>
</Grid>
</UserControl>
Edit:
What I'm trying to hide are the two values circled in red.
<oxy:Plot.Resources>
<Style TargetType="TextBlock">
<Style.Triggers>
<Trigger Property="Text" Value="360°">
<Setter Property="Visibility" Value="Collapsed"/>
</Trigger>
<Trigger Property="Text" Value="0°">
<Setter Property="Visibility" Value="Collapsed"/>
</Trigger>
</Style.Triggers>
</Style>
</oxy:Plot.Resources>

WPF window appearance is not same with design view

I create WPF application. I want to create borderless window. For that my code as follow
<Window x:Class="AzLeks.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
ResizeMode="CanMinimize" Height="600.586" Width="826.694" WindowStyle="None" AllowsTransparency="False"
MouseLeftButtonDown="MainWindow_OnMouseLeftButtonDown" Loaded="Window_Loaded"
WindowStartupLocation="CenterScreen">
<!--<Window.Background>
<ImageBrush ImageSource="images/bckgr.png" />
</Window.Background>-->
<Window.Resources>
<Style x:Key="Close" TargetType="Button">
<Style.Triggers>
<Trigger Property="IsMouseOver" Value="True">
<Setter Property="Cursor" Value="Hand" />
<Setter Property="Background" Value="Red" />
</Trigger>
</Style.Triggers>
</Style>
</Window.Resources>
<Grid Margin="-9,-13,-9,-16" HorizontalAlignment="Center" Background="Transparent" VerticalAlignment="Center" Height="630" Width="845">
<Grid.RowDefinitions>
<RowDefinition Height="235*" />
<RowDefinition />
</Grid.RowDefinitions>
<Border CornerRadius="12" BorderBrush="Transparent" BorderThickness="1" >
<Border.Background>
<ImageBrush ImageSource="/images/bckgr.png"></ImageBrush>
</Border.Background>
</Border>
<!--Some Content-->
</Grid>
In design mode it shown as follow:
But after runing the app it shown as:
I don't know what is a problem here. PLease help me, I can't find solution for this
Something like this.
<Window x:Class="AzLeks.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
ResizeMode="CanMinimize" Height="600" Width="820" WindowStyle="None" AllowsTransparency="True" Background="Transparent" MouseLeftButtonDown=" MainWindow_OnMouseLeftButtonDown" Loaded="Window_Loaded" WindowStartupLocation="CenterScreen">
<Window.Resources>
<Style x:Key="Close" TargetType="Button">
<Style.Triggers>
<Trigger Property="IsMouseOver" Value="True">
<Setter Property="Cursor" Value="Hand" />
<Setter Property="Background" Value="Red" />
</Trigger>
</Style.Triggers>
</Style>
</Window.Resources>
<Border CornerRadius="12" BorderBrush="Transparent" BorderThickness="1" >
<Border.Background>
<ImageBrush ImageSource="/images/bckgr.png"></ImageBrush>
</Border.Background>
<Grid HorizontalAlignment="Center" Background="Transparent" VerticalAlignment="Center" >
<Grid.RowDefinitions>
<RowDefinition Height="235*" />
<RowDefinition />
</Grid.RowDefinitions>
<!--Some Content-->
</Grid>
</Border>

Creating styles for a ListView in a WPF Desktop application

I have some styles for a Metro/win8 app:
<Style TargetType="ListViewItem">
<Setter Property="Background" >
<Setter.Value>
<SolidColorBrush Color="#FF171717" Opacity="0.70"/>
</Setter.Value>
</Setter>
<Setter Property="BorderBrush" Value="#FFEAF32C" />
<Setter Property="BorderThickness" Value="2, 0, 0, 0" />
<Setter Property="Padding" Value="5" />
<Setter Property="Opacity" Value="40" />
</Style>
But now I am making a desktop app in wpf (.net 4.5) and cannot apply styles like this in xaml to a ListView control. How do we define our own custom styles for a Desktop ListView control in xaml?
Here is an example putting the style in a windows resource dictionary.
<Window x:Class="WpfApplication2.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Height="350" Width="525">
<Window.Resources>
<Style TargetType="ListViewItem">
<Setter Property="Background" >
<Setter.Value>
<SolidColorBrush Color="#FF171717" Opacity="0.70"/>
</Setter.Value>
</Setter>
<Setter Property="BorderBrush" Value="#FFEAF32C" />
<Setter Property="BorderThickness" Value="2, 0, 0, 0" />
<Setter Property="Padding" Value="5" />
<Setter Property="Opacity" Value="40" />
</Style>
</Window.Resources>
<Grid>
<ScrollViewer HorizontalContentAlignment="Stretch" VerticalAlignment="Stretch">
<ListView>
<ListView.Items>
<Button>a</Button>
<Button>b</Button>
<Button>c</Button>
<Button>d</Button>
<Button>e</Button>
</ListView.Items>
</ListView>
</ScrollViewer>
</Grid>
</Window>
and if you want the style to be placed in it's own file then you can reference that file like this (my resource file is just call Dictionary1.xaml)
<Window x:Class="WpfApplication2.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Height="350" Width="525">
<Window.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="Dictionary1.xaml"/>
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Window.Resources>
<Grid>
<ScrollViewer HorizontalContentAlignment="Stretch" VerticalAlignment="Stretch">
<ListView>
<ListView.Items>
<Button>a</Button>
<Button>b</Button>
<Button>c</Button>
<Button>d</Button>
<Button>e</Button>
</ListView.Items>
</ListView>
</ScrollViewer>
</Grid>
</Window>

Categories

Resources