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>
Related
I'm styling the Grid controls to be the table headers using resources like so:
<Grid.Resources>
<Style TargetType="TextBlock">
<Setter Property="Padding" Value="5,10" />
<Setter Property="Foreground" Value="{StaticResource ForegroundDarkBrush}" />
<Setter Property="FontWeight" Value="Bold" />
<Setter Property="HorizontalAlignment" Value="Center" />
</Style>
<Style TargetType="Border">
<Setter Property="BorderThickness" Value="0.0,1.0,0.0,0" />
<Setter Property="BorderBrush" Value="{StaticResource ForegroundDarkBrush}" />
<Setter Property="Background" Value="{StaticResource BackgroundLightBrush}" />
</Style>
</Grid.Resources>
The thing is, I need to apply that resources into multiple places in my app, which leads to the code being repeated.
I was wondering if this is possible to store the resources in my App.xaml and use them by the key or something like that? Like so:
<Resources Key="MyResourceSet">
<Style>
[..]
</Style>
</Resources>
<Grid Resource="MyResourceSet">
[...]
</Grid>
Place the Style in the App.Resources like you would in any other UIElement.
<Application x:Class="Question_Answer_WPF_App.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
StartupUri="MainWindow.xaml">
<Application.Resources>
<Style x:Key="MyButtonStyle"
TargetType="Button">
<Setter Property="Background"
Value="Green" />
<Setter Property="Height"
Value="30" />
<Setter Property="Width"
Value="100" />
</Style>
</Application.Resources>
</Application>
Reference wherever you want in your app.
<Window x:Class="Question_Answer_WPF_App.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
Title="MainWindow"
Height="450"
Width="800">
<Button Content="Testing"
Style="{StaticResource MyButtonStyle}" />
</Window>
Another way to do this if you want several ResourceDictionary's to be used across your app; but with the same inner keys, is to reference the unique ResourceDictionary per element that will use it. This will not be using the App.xaml resources but will be pointing directly to the file location in your application. Since ResourceDictionary's have a default 'Build Action' of 'Page' it will work referencing the location this way. If your ResourceDictionary doesn't work this way the first thing is to check this by right clicking the ResourceDictionary in your solution explorer and make sure that's correct.
Example:
MyCustomResourcesA.xaml
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<Style TargetType="TextBlock">
<Setter Property="FontSize"
Value="46" />
</Style>
<Style x:Key="MyButtonStyle"
TargetType="Button">
<Setter Property="Background"
Value="Green" />
<Setter Property="Height"
Value="30" />
<Setter Property="Width"
Value="100" />
</Style>
</ResourceDictionary>
MyCustomResourcesB.xaml
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:Question_Answer_WPF_App">
<Style TargetType="TextBlock">
<Setter Property="FontSize"
Value="26" />
</Style>
<Style x:Key="MyButtonStyle"
TargetType="Button">
<Setter Property="Background"
Value="Blue" />
<Setter Property="Height"
Value="20" />
<Setter Property="Width"
Value="200" />
</Style>
</ResourceDictionary>
MainWindow.xaml
<Window x:Class="Question_Answer_WPF_App.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
Title="MainWindow"
Height="450"
Width="800">
<StackPanel HorizontalAlignment="Left">
<StackPanel>
<StackPanel.Resources>
<ResourceDictionary Source="MyCustomResourcesA.xaml" />
</StackPanel.Resources>
<TextBlock Text="I'm using MyCustomResourcesA" />
<Button Content="Testing"
Style="{StaticResource MyButtonStyle}" />
</StackPanel>
<StackPanel>
<StackPanel.Resources>
<ResourceDictionary Source="MyCustomResourcesB.xaml" />
</StackPanel.Resources>
<TextBlock Text="I'm using MyCustomResourcesB" />
<Button Content="Testing"
Style="{StaticResource MyButtonStyle}" />
</StackPanel>
</StackPanel>
</Window>
Looks like:
A user control's background is set, but that background hides the contained controls. How can this be resolved?
<UserControl x:Class="PL_Wpf.CustomControls.Conditioner"
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:PL_Wpf.CustomControls"
mc:Ignorable="d" Height="166" Width="349">
<UserControl.Background>
<ImageBrush ImageSource="Conditioner.png" Stretch="None"/>
</UserControl.Background>
<Grid >
<ComboBox x:Name="combo1" HorizontalAlignment="Right" Width="57" Margin="0,68,53.206,70" />
<ToggleButton x:Name="ToggleSwitch" Height="50" Click="ToggleSwitch_Click" Margin="97.205,55,115.206,61" d:LayoutOverrides="Width" >
<ToggleButton.Style>
<Style TargetType="{x:Type ToggleButton}">
<Style.Triggers>
<Trigger Property="IsChecked" Value="True">
<Setter Property="Content">
<Setter.Value>
<Image Source="../Pics/switch_on.png" />
</Setter.Value>
</Setter>
</Trigger>
<Trigger Property="IsChecked" Value="False">
<Setter Property="Content">
<Setter.Value>
<Image Source="../Pics/switch_off.png" />
</Setter.Value>
</Setter>
</Trigger>
</Style.Triggers>
</Style>
</ToggleButton.Style>
</ToggleButton>
</Grid>
jsfiddle.net/wgfw1Ld7/
The Margin properties on the controls set themselves when dropped on the design surface. This feature may be needed if adjusting items on a Canvas but are mostly an annoyance when dealing with most Xaml control placement.
Remove the Margin properties to see the controls in their correct location on the grid.
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>
I have following UserControl defined in wpf:
<UserControl x:Class="Views.HideShowDetailsView"
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"
mc:Ignorable="d">
<DockPanel Background="#FFFFF2CC" Name="HideShowDetailsPanel">
<Button Name="hidePatientDetails"
Background="Transparent"
Margin="10,10"
Width="40"
BorderBrush="Transparent"
BorderThickness="0"
DockPanel.Dock="Right"
Command="{Binding Path=HideDetailsCommand}" >
<Button.Template>
<ControlTemplate TargetType="Button">
<Image Source="../Resources/ArrowRight.png" />
</ControlTemplate>
</Button.Template>
</Button>
</DockPanel>
</UserControl>
And I need to change it's content by adding image canvas and another button when Command is activated. How this can be achieved in wpf?
You can do it by adding the two new controls to a container, say, StackPanel somewhere inside your UC. Then assign the following style to the StackPanel:
<Style x:Key="stackStyle" TargetType="StackPanel">
<Setter Property="Visibility" Value="Visible" />
<Style.Triggers>
<DataTrigger Binding="{Binding IsEnabled, ElementName=hidePatientDetails}" Value="False">
<Setter Property="Visibility" Value="Collapsed" />
</DataTrigger>
</Style.Triggers>
</Style>
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>