I have a xaml without a x:Class, this xaml has command bindings for some buttons. I want to add a new button and add some functionality to this button.
If I add x:Class, I get the error this class doesn't have the command methods.
How can I know, where are the commands implemented? How can I functionality to my button?
PS: I am working iwth the Vault Standards project from Autodesk
This is my xaml:
<WPF:MainWindow
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
x:Name="FileWindow"
xmlns:WPF="clr-namespace:CreateObject.WPF;assembly=CreateObject"
AllowsTransparency="False" Background="#F0F0F0" ResizeMode="NoResize" SizeToContent="WidthAndHeight">
<Window.Resources>
<Style x:Key="DynamicDataGridCellStyle" TargetType="{x:Type DataGridCell}">
<Setter Property="KeyboardNavigation.IsTabStop" Value="False" />
<Setter Property="Template">
<Setter.Value>
<ControlTemplate>
<ComboBox ItemsSource="{Binding ListValues}"
Text="{WPF:ValidatedBinding Value, StringFormat=N}" IsEditable="True"
BorderThickness="0" />
</ControlTemplate>
</Setter.Value>
</Setter>
<Style.Triggers>
<Trigger Property="IsSelected" Value="True">
<Setter Property="Background" Value="{DynamicResource {x:Static SystemColors.HighlightBrushKey}}" />
<Setter Property="Foreground"
Value="{DynamicResource {x:Static SystemColors.HighlightTextBrushKey}}" />
<Setter Property="BorderBrush" Value="{DynamicResource {x:Static SystemColors.HighlightBrushKey}}" />
</Trigger>
<Trigger Property="IsKeyboardFocusWithin" Value="True">
<Setter Property="BorderBrush" Value="{DynamicResource {x:Static DataGrid.FocusBorderBrushKey}}" />
</Trigger>
<DataTrigger Binding="{Binding EnforceListValues}" Value="True">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate>
<ComboBox ItemsSource="{Binding ListValues}" SelectedItem="{WPF:ValidatedBinding Value}"
BorderThickness="0"/>
</ControlTemplate>
</Setter.Value>
</Setter>
</DataTrigger>
<DataTrigger Binding="{Binding ListValues.Count}" Value="0">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate>
<TextBox Text="{WPF:ValidatedBinding Value, StringFormat=N}" BorderThickness="0" CharacterCasing="{Binding Case}" />
</ControlTemplate>
</Setter.Value>
</Setter>
</DataTrigger>
<DataTrigger Binding="{Binding Typ}" Value="DateTime">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate>
<DatePicker SelectedDate="{WPF:ValidatedBinding Value}" SelectedDateFormat="Short"/>
</ControlTemplate>
</Setter.Value>
</Setter>
</DataTrigger>
<DataTrigger Binding="{Binding Typ}" Value="Bool">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate>
<ComboBox Text="{WPF:ValidatedBinding Value}" IsEditable="True">
<ComboBoxItem Content="True" />
<ComboBoxItem Content="False" />
</ComboBox>
</ControlTemplate>
</Setter.Value>
</Setter>
</DataTrigger>
</Style.Triggers>
</Style>
<Style x:Key="DynamicDataGridLabelStyle" TargetType="{x:Type DataGridCell}">
<Setter Property="KeyboardNavigation.IsTabStop" Value="False" />
<Setter Property="Height" Value="22" />
<Setter Property="Margin" Value="0,4,0,0" />
<Setter Property="BorderThickness" Value="0" />
<Setter Property="IsHitTestVisible" Value="False" />
</Style>
<Style TargetType="{x:Type Label}" BasedOn="{StaticResource {x:Type Label}}">
<Setter Property="Margin" Value="0,0,0,0" />
<Setter Property="Padding" Value="5,3,3,2" />
<Setter Property="VerticalAlignment" Value="Stretch" />
<Setter Property="HorizontalAlignment" Value="Stretch" />
<Setter Property="BorderBrush" Value="#FFABADB3" />
<Setter Property="BorderThickness" Value="1,1,1,0" />
<Style.Triggers>
<DataTrigger Binding="{Binding Content, RelativeSource={RelativeSource Self}}" Value="{x:Null}">
<Setter Property="BorderThickness" Value="1" />
<Setter Property="BorderBrush" Value="#ff0000" />
</DataTrigger>
</Style.Triggers>
</Style>
<Style TargetType="{x:Type TextBox}" BasedOn="{StaticResource {x:Type TextBox}}">
<Setter Property="Margin" Value="0,0,0,0" />
<Setter Property="VerticalAlignment" Value="Stretch" />
<Setter Property="HorizontalAlignment" Value="Stretch" />
<Setter Property="VerticalContentAlignment" Value="Center" />
<Setter Property="BorderBrush" Value="#FFABADB3" />
<Setter Property="BorderThickness" Value="0,1,1,0" />
<Setter Property="Padding" Value="5,3,3,2" />
<Setter Property="TextWrapping" Value="Wrap"></Setter>
<Style.Triggers>
<Trigger Property="Validation.HasError" Value="true">
<Setter Property="ToolTip"
Value="{Binding (Validation.Errors)[0].ErrorContent, RelativeSource={x:Static RelativeSource.Self}}" />
</Trigger>
<DataTrigger Binding="{Binding IsReadOnly, RelativeSource={RelativeSource Self}}" Value="True">
<Setter Property="Background" Value="{DynamicResource {x:Static SystemColors.WindowColorKey}}" />
</DataTrigger>
</Style.Triggers>
</Style>
<Style TargetType="{x:Type ComboBox}" BasedOn="{StaticResource {x:Type ComboBox}}">
<Setter Property="Margin" Value="0,0,0,0" />
<Setter Property="VerticalContentAlignment" Value="Center" />
<Setter Property="VerticalAlignment" Value="Stretch" />
<Setter Property="HorizontalAlignment" Value="Stretch" />
<Setter Property="Background" Value="{DynamicResource {x:Static SystemColors.ControlLightLightBrushKey}}" />
<Setter Property="BorderBrush" Value="#FFABADB3" />
<Setter Property="BorderThickness" Value="0,1,1,0" />
<Style.Triggers>
<Trigger Property="Validation.HasError" Value="true">
<Setter Property="ToolTip"
Value="{Binding (Validation.Errors)[0].ErrorContent, RelativeSource={x:Static RelativeSource.Self}}" />
</Trigger>
</Style.Triggers>
</Style>
<Style TargetType="{x:Type DatePicker}">
<Setter Property="Height" Value="22" />
<Style.Triggers>
<Trigger Property="Validation.HasError" Value="true">
<Setter Property="ToolTip"
Value="{Binding (Validation.Errors)[0].ErrorContent, RelativeSource={x:Static RelativeSource.Self}}" />
</Trigger>
</Style.Triggers>
</Style>
<Style x:Key="Required" TargetType="{x:Type TextBox}" BasedOn="{StaticResource {x:Type TextBox}}">
<Style.Triggers>
<DataTrigger Binding="{Binding Text, RelativeSource={RelativeSource Self}}" Value="">
<Setter Property="BorderBrush" Value="Red" />
<Setter Property="BorderThickness" Value="1,1,1,1" />
</DataTrigger>
</Style.Triggers>
</Style>
<Style x:Key="NumSchmCtrlStyle" TargetType="{x:Type WPF:DSNumSchemeCtrl}">
<Setter Property="Height" Value="Auto" />
<Setter Property="ToolTipService.ShowOnDisabled" Value="True" />
<Setter Property="BorderBrush" Value="Gray" />
<Setter Property="BorderThickness" Value="0,1,1,0" />
<Style.Triggers>
<DataTrigger Binding="{Binding EditMode}" Value="True">
<Setter Property="Visibility" Value="Collapsed" />
</DataTrigger>
</Style.Triggers>
</Style>
<Style x:Key="DocTypeStyle" TargetType="{x:Type ComboBox}" BasedOn="{StaticResource {x:Type ComboBox}}">
<Style.Triggers>
<DataTrigger Binding="{Binding EditMode}" Value="True">
<Setter Property="Visibility" Value="Collapsed" />
</DataTrigger>
</Style.Triggers>
</Style>
<Style x:Key="TemplateCbStyle" TargetType="{x:Type ComboBox}" BasedOn="{StaticResource {x:Type ComboBox}}">
<Style.Triggers>
<DataTrigger Binding="{Binding CreateMode}" Value="True">
<Setter Property="ItemsSource" Value="{Binding Templates}" />
</DataTrigger>
<DataTrigger Binding="{Binding EditMode}" Value="True">
<Setter Property="Visibility" Value="Collapsed" />
</DataTrigger>
<DataTrigger Binding="{Binding ElementName=TemplateTB, Path=Visibility}" Value="Visible">
<Setter Property="Visibility" Value="Collapsed" />
</DataTrigger>
</Style.Triggers>
</Style>
<Style x:Key="ButtonGridStyle" TargetType="{x:Type Grid}">
<Setter Property="Margin" Value="0,15,2,5" />
</Style>
<!-- This XmlDataProvider is used for defining Name/TemplatePath pairs that are used in the combo box "Document Type" and can be easily extended -->
<XmlDataProvider x:Key="DocTypes"
Source="C:\ProgramData\Autodesk\Vault 2020\Extensions\DataStandard\Vault\Configuration\File.xml"
XPath="/DocTypeData" />
<BooleanToVisibilityConverter x:Key="BooleanToVisibilityConverter" />
</Window.Resources>
<Grid x:Name="grdMain" Margin="5">
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" />
<ColumnDefinition />
</Grid.ColumnDefinitions>
<Grid x:Name="grdGeneralProps" Margin="0"
ToolTip="{Binding UIString[LBL73], FallbackValue='General Properties'}"
Width="Auto">
<Grid.RowDefinitions>
<RowDefinition Height="auto" />
<RowDefinition Height="auto" />
<RowDefinition Height="auto" />
<RowDefinition Height="auto" />
<RowDefinition Height="auto" />
<RowDefinition Height="auto" />
<RowDefinition Height="auto" />
<RowDefinition Height="auto" />
<RowDefinition Height="auto" />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="140"/>
<ColumnDefinition Width="220"/>
</Grid.ColumnDefinitions>
<Label Content="{Binding UIString[LBL8], FallbackValue=Categories}" Grid.Row="0" Grid.Column="0" />
<ComboBox x:Name="Categories" ItemsSource="{Binding PsList[GetCategories], Mode=OneTime}"
DisplayMemberPath="Name" SelectedItem="{Binding DynamicPropertiesCategory}"
SelectedValuePath="Name" SelectedValue="{Binding Prop[_Category].Value}"
Grid.Row="0" Grid.Column="1"
IsEnabled="{Binding CreateMode}" />
<Label Content="{Binding UIString[LBL23], FallbackValue=DocTypes}" Grid.Row="1" Grid.Column="0"
Visibility="{Binding Visibility, ElementName=DocTypeCombo}" />
<ComboBox ItemsSource="{Binding Source={StaticResource DocTypes}, XPath=DocTypeInfo}"
x:Name="DocTypeCombo"
Grid.Row="1"
Grid.Column="1"
IsEnabled="{Binding CreateMode}"
DisplayMemberPath="DocName"
SelectedValuePath="Path"
SelectedValue="{Binding TemplatePath}"
SelectedIndex="0"
Style="{StaticResource DocTypeStyle}" />
<Label Content="{Binding UIString[LBL9], FallbackValue=Templates}" Grid.Row="2" Grid.Column="0" >
<Label.Style>
<Style TargetType="{x:Type Label}">
<Setter Property="BorderBrush" Value="#FFABADB3" />
<Setter Property="BorderThickness" Value="1,1,1,0" />
<Style.Triggers>
<MultiDataTrigger>
<MultiDataTrigger.Conditions>
<Condition Binding="{Binding EditMode}" Value="True" />
<Condition Binding="{Binding Visibility, ElementName=TemplateCB}"
Value="Collapsed" />
</MultiDataTrigger.Conditions>
<Setter Property="Visibility" Value="Collapsed" />
</MultiDataTrigger>
</Style.Triggers>
</Style>
</Label.Style>
</Label>
<ComboBox x:Name="TemplateCB" Grid.Row="2" Grid.Column="1" IsSynchronizedWithCurrentItem="True"
SelectedItem="{Binding SelectedTemplate}" Style="{StaticResource TemplateCbStyle}" />
<TextBox x:Name="TemplateTB" Grid.Row="2" Grid.Column="1" Text="{Binding UIString[LBL28]}" IsHitTestVisible="False">
<TextBox.Style>
<Style TargetType="{x:Type TextBox}">
<Setter Property="TextWrapping" Value="Wrap"></Setter>
<Setter Property="Visibility" Value="Collapsed" />
<Style.Triggers>
<MultiDataTrigger>
<MultiDataTrigger.Conditions>
<Condition Binding="{Binding SelectedItem, ElementName=TemplateCB}"
Value="{x:Null}" />
<Condition Binding="{Binding CreateMode}" Value="True" />
</MultiDataTrigger.Conditions>
<Setter Property="Visibility" Value="Visible" />
<Setter Property="Background" Value="#F0F0F0" />
</MultiDataTrigger>
</Style.Triggers>
</Style>
</TextBox.Style>
</TextBox>
<Label Content="{Binding UIString[LBL10],FallbackValue=Numberingscheme}" Grid.Column="0" Grid.Row="3"
Visibility="{Binding Visibility, ElementName=NumSchms}" />
<ComboBox Grid.Column="1" Grid.Row="3"
x:Name="NumSchms" DisplayMemberPath="Name"
SelectedValuePath="Name"
SelectedValue="{Binding Prop[_NumSchm].Value}"
ItemsSource="{Binding PsList[GetNumSchms], Mode=OneTime}"
IsEnabled="{Binding HasItems, RelativeSource={RelativeSource Self}}"
Visibility="{Binding NotEditMode, Converter={StaticResource BooleanToVisibilityConverter}}" />
<Label Content="{Binding UIString[LBL31], FallbackValue=Number}" Grid.Column="0" Grid.Row="4" Height="Auto"
Visibility="{Binding Visibility, ElementName=DSNumSchmsCtrl}" />
<WPF:DSNumSchemeCtrl Grid.Column="1" Grid.Row="4" x:Name="DSNumSchmsCtrl"
IsEnabled="{Binding ElementName=NumSchms, Path=IsEnabled}"
Scheme="{Binding ElementName=NumSchms, Path=SelectedItem}"
GeneratedNumberProperty="_GeneratedNumber" Style="{StaticResource NumSchmCtrlStyle}" />
<Label Content="{Binding UIString[LBL5],FallbackValue=Path}" Grid.Column="0" Grid.Row="6"
BorderThickness="1" />
<TextBox Text="{WPF:ValidatedBinding Prop[_FilePath].Value}" Grid.Column="1" Grid.Row="6" IsReadOnly="True"
IsTabStop="False" BorderThickness="0,1,1,1" />
<Label Content="{Binding UIString[LBL6],FallbackValue=Filename}" Grid.Row="5" Grid.Column="0"
Visibility="{Binding NumSchmFieldsEmpty, ElementName=DSNumSchmsCtrl, Converter={StaticResource BooleanToVisibilityConverter}}" />
<Grid Grid.Row="5" Grid.Column="1">
<TextBox Grid.Column="0" x:Name="FILENAME" Text="{WPF:ValidatedBinding Name}"
IsTabStop="False" Visibility="{Binding NumSchmFieldsEmpty, ElementName=DSNumSchmsCtrl, Converter={StaticResource BooleanToVisibilityConverter}}" />
<Button x:Name="TranslationButton" Content="..."
Grid.Column="1" Width="20"
HorizontalAlignment="Right" Height="24" IsCancel="True" />
<!-- -->
</Grid>
</Grid>
<DataGrid Grid.Column="1" x:Name="DSDynCatPropGrid" MaxHeight="350"
ItemsSource="{Binding DynamicProperties}"
ToolTip="{Binding UIString[LBL63], FallbackValue='Category Properties'}"
AutoGenerateColumns="False"
HeadersVisibility="Column"
ScrollViewer.CanContentScroll="True"
EnableRowVirtualization="False"
HorizontalGridLinesBrush="WhiteSmoke"
VerticalGridLinesBrush="WhiteSmoke" BorderBrush="Gray" MaxWidth="380"
Margin="5,0,0,0" VerticalAlignment="Top">
<DataGrid.Columns>
<DataGridTextColumn Binding="{Binding Name}" CellStyle="{StaticResource DynamicDataGridLabelStyle}"
MinWidth="140" Width="Auto" IsReadOnly="True">
<DataGridTextColumn.HeaderTemplate>
<DataTemplate>
<TextBlock
Text="{Binding DataContext.UIString[LBL64], RelativeSource={RelativeSource AncestorType={x:Type DataGrid}}}" />
</DataTemplate>
</DataGridTextColumn.HeaderTemplate>
</DataGridTextColumn>
<DataGridTextColumn Binding="{Binding Value}" Width="*"
CellStyle="{StaticResource DynamicDataGridCellStyle}" IsReadOnly="True">
<DataGridTextColumn.HeaderTemplate>
<DataTemplate>
<TextBlock
Text="{Binding DataContext.UIString[LBL65], RelativeSource={RelativeSource AncestorType={x:Type DataGrid}}}" />
</DataTemplate>
</DataGridTextColumn.HeaderTemplate>
</DataGridTextColumn>
</DataGrid.Columns>
</DataGrid>
<Grid x:Name="ButtonGrid" Style="{StaticResource ButtonGridStyle}" Grid.Row="2" Grid.ColumnSpan="2">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="80" />
<ColumnDefinition />
<ColumnDefinition Width="80" />
<ColumnDefinition Width="20" />
<ColumnDefinition Width="80" />
</Grid.ColumnDefinitions>
<Button x:Name="btnOK" Content="{Binding UIString[BTN1], FallbackValue=OK}"
Command="{Binding CloseWindowCommand, ElementName=FileWindow}" IsEnabled="{Binding IsNotReadonly}"
Grid.Column="2" Width="80" Height="24" IsDefault="True" />
<Button x:Name="btnEsc" Content="{Binding UIString[BTN2], FallbackValue=Esc}"
Command="{Binding CancelWindowCommand, ElementName=FileWindow}" Grid.Column="4" Width="80"
HorizontalAlignment="Right" Height="24" IsCancel="True" />
<Button x:Name="MyButtonCopied" Content="{Binding UIString[BTN2], FallbackValue=Esc}"
Command="{Binding CancelWindowCommand, ElementName=FileWindow}" Grid.Column="1" Width="80"
HorizontalAlignment="Right" Height="24" IsCancel="True" />
</Grid>
</Grid>
Thanks
Assuming you are using Visual Studio, two ways to find where the .CS file is located: 1) add an event and have Visual Studio automatically create the event method. Visual studio will open the .CS file. Once open, you know where it is located. 2) right click on a property and select "Peek Definition". Once shown, hover over the CS filename and the hint will tell you where the file is located.
I'm looking to be able to modify the default Pivot template to change the size of the Pivot Item headers. How might I do this with the following Style
<Style x:Key="PivotStyle" TargetType="phone:Pivot">
<Setter Property="Margin" Value="0"/>
<Setter Property="Padding" Value="0"/>
<Setter Property="Foreground" Value="{StaticResource PhoneForegroundBrush}"/>
<Setter Property="Background" Value="Transparent"/>
<Setter Property="ItemsPanel">
<Setter.Value>
<ItemsPanelTemplate>
<Grid/>
</ItemsPanelTemplate>
</Setter.Value>
</Setter>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="phone:Pivot">
<Grid HorizontalAlignment="{TemplateBinding HorizontalAlignment}"
VerticalAlignment="{TemplateBinding VerticalAlignment}">
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<Grid CacheMode="BitmapCache" Grid.RowSpan="2" >
<Grid.Background>
<LinearGradientBrush StartPoint="0,0" EndPoint="0,1">
<GradientStop Color="Transparent" Offset="0.0" />
<GradientStop Color="Transparent" Offset="1.0" />
</LinearGradientBrush>
</Grid.Background>
</Grid>
<Grid Background="{TemplateBinding Background}" CacheMode="BitmapCache" Grid.Row="2" />
<ContentPresenter ContentTemplate="{TemplateBinding TitleTemplate}" Content="{TemplateBinding Title}" Margin="24,17,0,-7" />
<Primitives:PivotHeadersControl x:Name="HeadersListElement" Foreground="{StaticResource PhoneForegroundBrush}" FontSize="28" Grid.Row="1"/>
<ItemsPresenter x:Name="PivotItemPresenter" Margin="{TemplateBinding Padding}" Grid.Row="2"/>
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
I am trying to get this to mimick the following
You can surely change your Pivot Header's font-size, family and so on by changing HeaderTemplate:
<phone:Pivot Title="PivotTest" Style="{StaticResource PivotStyle}">
<phone:Pivot.HeaderTemplate>
<DataTemplate>
<TextBlock Text="{Binding}" FontSize="10"/>
</DataTemplate>
</phone:Pivot.HeaderTemplate>
<phone:PivotItem Header="One">
// item 1
</phone:PivotItem>
<phone:PivotItem Header="Two">
// item 2
</phone:PivotItem>
</phone:Pivot>
EDIT - within a style:
<phone:PhoneApplicationPage.Resources>
<DataTemplate x:Key="myHeader">
<TextBlock Text="{Binding}" FontSize="10"/>
</DataTemplate>
<Style x:Key="PivotStyle" TargetType="phone:Pivot">
<Setter Property="HeaderTemplate" Value="{StaticResource myHeader}"/>
<Setter Property="Margin" Value="0"/>
....
I have been using a general custom Pivot style in my app, but it is changing the header foreground as well as body foreground to the same color (Blue). I only need the header foreground to change accordingly to my specifications, but the body foreground should remain to be the default application foreground. How might I make that change in the following template?
<Style x:Key="PivotStyleBlue" TargetType="phone:Pivot">
<Setter Property="Margin" Value="0"/>
<Setter Property="Padding" Value="0"/>
<!--<Setter Property="Foreground" Value="{StaticResource PhoneForegroundBrush}"/>-->
<Setter Property="Foreground" Value="Blue"/>
<Setter Property="Background" Value="Transparent"/>
<Setter Property="ItemsPanel">
<Setter.Value>
<ItemsPanelTemplate>
<Grid/>
</ItemsPanelTemplate>
</Setter.Value>
</Setter>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="phone:Pivot">
<Grid HorizontalAlignment="{TemplateBinding HorizontalAlignment}"
VerticalAlignment="{TemplateBinding VerticalAlignment}">
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<Grid CacheMode="BitmapCache" Grid.RowSpan="2" >
<Grid.Background>
<LinearGradientBrush StartPoint="0,0" EndPoint="0,1">
<GradientStop Color="Transparent" Offset="0.0" />
<GradientStop Color="Transparent" Offset="1.0" />
</LinearGradientBrush>
</Grid.Background>
</Grid>
<Grid Background="{TemplateBinding Background}" CacheMode="BitmapCache"
Grid.Row="2" />
<ContentPresenter ContentTemplate="{TemplateBinding TitleTemplate}"
Content="{TemplateBinding Title}" Margin="24,17,0,-7"/>
<Primitives:PivotHeadersControl x:Name="HeadersListElement"
Grid.Row="1"/>
<ItemsPresenter x:Name="PivotItemPresenter"
Margin="{TemplateBinding Padding}" Grid.Row="2"/>
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
Change Foreground of HeadersListElement only.
<Primitives:PivotHeadersControl
x:Name="HeadersListElement"
Foreground="Blue"
Grid.Row="1" />
Why does this xaml code not work?
<Page
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<Grid>
<Grid.Resources>
<ControlTemplate x:Key="btnTemplate" TargetType="{x:Type Button}">
<Grid>
<Ellipse Name="el1" Fill="Orange" Width="100" Height="100" />
<ContentPresenter VerticalAlignment="Center" HorizontalAlignment="Center" />
</Grid>
<ControlTemplate.Triggers>
<Trigger Property="Button.IsMouseOver" Value="True">
<Setter TargetName="el1" Property="Background" Value="Blue" />
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Grid.Resources>
<Button Content="Klick mich" Template="{StaticResource btnTemplate}"/>
</Grid>
</Page>
You are trying to set the Background property in your Trigger, but the Ellipse doesn't have a Background property. It has a Fill property. So you need to use:
<Grid>
<Grid.Resources>
<ControlTemplate x:Key="btnTemplate" TargetType="{x:Type Button}">
<Grid>
<Ellipse Name="el1" Fill="Orange" Width="100" Height="100" />
<ContentPresenter VerticalAlignment="Center" HorizontalAlignment="Center" />
</Grid>
<ControlTemplate.Triggers>
<Trigger Property="Button.IsMouseOver" Value="True">
<Setter TargetName="el1" Property="Fill" Value="Blue" />
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Grid.Resources>
<Button Content="Klick mich" Template="{StaticResource btnTemplate}" />
</Grid>
I Have a ItemTemplate in which is a simple button bound on a command, which can be executable or not depending on some property.
I'd like the color of this button's background to change if the command isn't executable.
I tried several methods, but I can't find anyway to do this purely in XAML (I'm doing this in a study context, and code behind isn't allowed).
Here's my code for the button :
<Button x:Name="Dispo" HorizontalAlignment="Center" Margin="0" VerticalAlignment="Center" Width="30" Height="30"
Grid.Column="2" Grid.Row="0"
Command="{Binding AddEmpruntCommandModel.Command}"
CommandParameter="{Binding ElementName='flowCars', Path='SelectedItem'}"
vm:CreateCommandBinding.Command="{Binding AddEmpruntCommandModel}" >
<Button.Style>
<Style TargetType="{x:Type Button}">
<Style.Triggers>
<Trigger Property="IsEnabled" Value="True">
<Setter Property="Button.Background" Value="Green"/>
</Trigger>
<Trigger Property="IsEnabled" Value="False">
<Setter Property="Button.Background" Value="Red"/>
</Trigger>
</Style.Triggers>
</Style>
</Button.Style>
</Button>
You can specify your own template like that:
<Button Content="OK" Command="{Binding SomeCommand}">
<Button.Style>
<Style>
<Setter Property="Button.Template">
<Setter.Value>
<ControlTemplate TargetType="Button">
<Border x:Name="Border" Background="Green">
<ContentPresenter HorizontalAlignment="Center" VerticalAlignment="Center" />
</Border>
<ControlTemplate.Triggers>
<Trigger Property="IsEnabled" Value="false">
<Setter TargetName="Border" Property="Background" Value="Red" />
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</Button.Style>
</Button>