Accessing DataGridColumn property from DataTrigger in CellTemplate - triggers

I created own custom attached property on DataGridColumn - utilities:ADPs.IsCellSelected to indicate whether any cell is selected in the column. I did similar for rows and it works fine.
Now I want to use this property to change the whole column e.g. background property like:
<DataGridTemplateColumn x:Name="MyColumn" Header="Test">
<DataGridTemplateColumn.CellStyle>
<Style TargetType="DataGridCell" BasedOn="{StaticResource BaseCell}">
<Setter Property="Background" Value="Black"/>
</Style>
</DataGridTemplateColumn.CellStyle>
<DataGridTemplateColumn.CellTemplate>
<DataTemplate x:Uid="DataTemplate_3">
<TextBlock x:Name="trg" Text="some text" />
<DataTemplate.Triggers>
<Trigger SourceName="MyColumn" Property="utilities:ADPs.IsCellSelectedColumn" Value="True">
<Setter TargetName="trg" Property="Background" Value="Red"/>
</Trigger>
</DataTemplate.Triggers>
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>
But VS shows an error "The name MyColumn is not recognized.". Any idea how I can access to my new attached DataGridColumn property from "cells"?.
EDIT:
Probably i ti sno t possible what I intend because:
"DataTemplate has its own NameScope, therefore you cannot refer to an element outside DataTemplate using ElementName. Moreover, DataGridTemplateColumn is not an UIElement and is not in VisualTree, therefore DataGridTemplateColumn is not parent of your elements defined in DataTemplate. DataGridTemplateColumn is used just to define columns. DataGrid then generate headers, rows and cells based on the definitions, but the DataGridColumns never gets rendered."
link

Instead to change Background property of whole column with selected cell, I change only column header Background property. I use my custom attached property on DataGridColumnHeader - utilities:ADPs.IsCellSelected and then highligth the header
<DataGridTemplateColumn.HeaderStyle>
<Style TargetType="DataGridColumnHeader">
<Style.Triggers>
<Trigger Property="utilities:ADPs.IsCellSelected" Value="True">
<Setter Property="Background" Value="Red"/>
</Trigger>
</Style.Triggers>
</Style>
</DataGridTemplateColumn.HeaderStyle>

Related

Set background color on mouse hover in comboboxitem WPF control

I am creating a WPF project .I am trying to remove this default background [marked in orange] on mouse hover from the combobox drop down. Below is the code which I have trying. I have tried multiple solutions available at various posts but the background color does not seems to change.
Thanks a lot in advance for the help !!
<ComboBox HorizontalAlignment="Left" Margin="95,44,0,0" VerticalAlignment="Top" Width="208">
<ComboBox.Resources>
<SolidColorBrush x:Key="{x:Static SystemColors.HighlightBrushKey}"
Color="Gray"/>
<Style TargetType="{x:Type ComboBoxItem}">
<Setter Property="Foreground" Value="Gray" />
<Setter Property="FocusVisualStyle" Value="{x:Null}"/>
<Setter Property="BorderThickness" Value="0"/>
<Setter Property="OverridesDefaultStyle" Value="True"/>
<Style.Triggers>
<Trigger Property="IsFocused" Value="True">
<Setter Property="Background" Value="#FFCDCDCD"/>
</Trigger>
<Trigger Property="IsMouseOver" Value="True">
<Setter Property="Background" Value="Red"/>
</Trigger>
</Style.Triggers>
</Style>
</ComboBox.Resources>
</<ComboBox>

WPF Cell Button Hide on certain condition

I have data source which, getting bind to grid in WPF. Data source is
array of students, with following fields
Name, Grade
Grid have 3 columns
Name, Grade, Settings
Settings column contains simple button for settings as below
<DataGridTemplateColumn Header="Settings" Width="75" CanUserResize="False">
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<Button Name="cSettings" Click="cSettings_Click" Style="{DynamicResource EditSettingsButton}" Width="50" >
</Button>
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>
Now, If grade is equal to one then only,Settings Button should get displayed.
Can I write condition in XAML itself ? i.e. Visibility of button should be on some condition ?
Tried below approach but not working
<DataTemplate>
<Button Name="cSettings" Click="cSettings_Click" Style="{DynamicResource EditSettingsButton}" Width="50" >
<Style TargetType="{x:Type Button}">
<Style.Triggers>
<DataTrigger Binding="{Binding Grade}" Value="1">
<Setter Property="Visibility" Value="Visible"></Setter>
</DataTrigger>
<DataTrigger Binding="{Binding Grade}" Value="2">
<Setter Property="Visibility" Value="Hidden"></Setter>
</DataTrigger>
</Style.Triggers>
</Style>
</Button>
</DataTemplate>
Thanks
You could try using a converter instead. See this link

Hide DataPoints in chart control from WinRT XAML Toolkit

Is it possible to hide the data points in the chart control from the WinRT XAML Toolkit from CodePlex? I'm using a LineSeries and only want a line without the dots.
This seems to work. Though I am not yet sure why it makes my lines orange...
<charting:Chart
x:Name="LineChart2"
Title="Line Chart Without Data Points"
Margin="70,0">
<charting:LineSeries
Title="Population"
IndependentValueBinding="{Binding Name}"
DependentValueBinding="{Binding Value}"
IsSelectionEnabled="True">
<charting:LineSeries.DataPointStyle>
<Style
TargetType="charting:LineDataPoint">
<Setter
Property="BorderThickness"
Value="0" />
<Setter
Property="IsTabStop"
Value="False" />
<Setter
Property="Width"
Value="0" />
<Setter
Property="Height"
Value="0" />
<Setter
Property="Template">
<Setter.Value>
<ControlTemplate
TargetType="charting:LineDataPoint">
<Grid
x:Name="Root"
Opacity="0" />
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</charting:LineSeries.DataPointStyle>
</charting:LineSeries>
</charting:Chart>
#Filip Skakun thanks for the very accurate answer, and about your issue regarding Orange Lines try adding this property and change the color to whatever color you want.
<Charting:LineSeries.DataPointStyle>
<Style TargetType="Charting:LineDataPoint">
<Setter Property="Background" Value="Red" />
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="Charting:LineDataPoint">
<Grid x:Name="Root" Opacity="0" />
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</Charting:LineSeries.DataPointStyle>
it happens mainly because Chart's are capable of displaying multiple data series on single chart. and for Series[0] the default color is set to Orange.

Styling button in MVVM

I am writing a small WPF application using MVVM pattern.
I set some style resources for buttons into my main window and I would like them to apply to the buttons into the views. The problem is that some of the buttons are having a style with trigger. So I would like to inherit this style from the generic one
here is my main window code:
<Window.Resources>
<DataTemplate DataType="{x:Type vm:HomeViewModel}">
<views:HomeView/>
</DataTemplate>
<DataTemplate DataType="{x:Type vm:DetailReportViewModel}">
<views:DetailReportView/>
</DataTemplate>
<DataTemplate DataType="{x:Type vm:TransferViewModel}">
<views:TransferView/>
</DataTemplate>
<Style TargetType="{x:Type Button}">
<Setter Property="Margin" Value="5"/>
<Setter Property="MinWidth" Value="30"/>
<Setter Property="Foreground" Value="Red"/>
</Style>
<Style TargetType="{x:Type ComboBox}">
<Setter Property="Margin" Value="5"/>
</Style>
</Window.Resources>
here is the button XAML into my view/usercontrol
<Button Content="Delete" Command="{Binding DeleteReportCommand}">
<Button.Style>
<Style TargetType="{x:Type Button}">
<Style.Triggers>
<DataTrigger Binding="{Binding Mode}">
<DataTrigger.Value>
<vm:Mode>Add</vm:Mode>
</DataTrigger.Value>
<Setter Property="Visibility" Value="Collapsed"/>
</DataTrigger>
<DataTrigger Binding="{Binding Mode}">
<DataTrigger.Value>
<vm:Mode>Edit</vm:Mode>
</DataTrigger.Value>
<Setter Property="Visibility" Value="Visible"/>
</DataTrigger>
</Style.Triggers>
</Style>
</Button.Style>
</Button>
I tried to used BasedOn="{StaticResource {x:Type Button} to inherit but it doesn't seems to work (see img)
I tried with a key name but static resource won't find the key name as it's not on the same view. And BasedOn is not accepting Dynamic resource.
Anything I am missing?
Thank you
You can put all the custom styles in a separate resource dictionary file and you can add it in usercontrol.resources.
Refer this: http://www.codeproject.com/Articles/35346/Using-a-Resource-Dictionary-in-WPF
Or you can put all those in app.xaml (Application.Resources).
Refer this: http://msdn.microsoft.com/en-us/library/system.windows.resourcedictionary.aspx

UWP Semantic Zoom, ListView, VisualState

<SemanticZoom x:Name="Zoom" >
<SemanticZoom.ZoomedInView>
<ListView Name="HotelInList"
IsItemClickEnabled="False"
Style="{StaticResource HotelListViewStyle}"
ItemContainerStyle="{StaticResource HotelListItemContainerStyle}"
ItemsSource="{Binding Source={StaticResource HotelViewSource}}"
ItemTemplate="{StaticResource HotelListItemTemplate}"
SelectedItem="{Binding Selected, Mode=TwoWay}" >
<Interactivity:Interaction.Behaviors>
<Core:EventTriggerBehavior EventName="ItemClick">
<Core:GoToStateAction StateName="DetailVisualState" />
</Core:EventTriggerBehavior>
</Interactivity:Interaction.Behaviors>
<ListView.GroupStyle>
The interactivity snippet above doesn't work. It will complain about how HotelInList doesn't contain a visual state named DetailVisualState, which is left out for brevity for now, but it is a visualstate above part of the rootlayout grid
Would nesting inside the SemanticZoom block the EventTriggerBehavior?
<Interactivity:Interaction.Behaviors>
<Core:EventTriggerBehavior EventName="ItemClick">
<Core:GoToStateAction StateName="DetailVisualState" TargetObject="{Binding ElementName=ThisPage}" />
</Core:EventTriggerBehavior>
</Interactivity:Interaction.Behaviors>
Where ThisPage is the x:Name of the actual page, which forces the interaction to look down the resource tree and find from the the available resources the visualstate you requested.