Access child property held within WPF resource from a buttons ControlTemplate
up vote
0
down vote
favorite
I have a resource that holds some icons made up of paths. Each icon in the resource is held within a canvas. An example is shown below.
<Canvas x:Key="Home_Icon" Width="41.5455" Height="33.2506">
<Path x:Name="Path1" Width="29.3385" Height="25.8615" Canvas.Left="6.0829" Canvas.Top="7.37233" Stretch="Fill" Fill="Red" Data="…"/>
<Path x:Name="Path2" Width="40.9841" Height="19.2586" Canvas.Left="0.262487" Canvas.Top="0.445261" Stretch="Fill" Fill="yellow" Data="…"/>
</Canvas>
The above resource is used in a ControlTemplate for a Button as shown below (the ViewBox loads the canvas from the resource).
<Style x:Key="button_home_style" TargetType="Button">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="Button">
<Border Padding="5,15" Background="{StaticResource background_color_light}">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="auto"/>
</Grid.RowDefinitions>
<Viewbox Child="{StaticResource Home_Icon}">
</Viewbox>
</Grid>
</Border>
<ControlTemplate.Triggers>
<Trigger Property="IsMouseOver" Value="True">
<Setter TargetName="Path1" Property="Fill" Value="{StaticResource foreground_color_highlight}"/>
<Setter TargetName="Path2" Property="Fill" Value="{StaticResource foreground_color_highlight}"/>
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
The problem
I want to be able to change the Fill colour property on Path1 and Path2 (these are the path data held within the canvas in the resource) when the IsMouseOver is triggered on the button but I am unsure how to locate these.
wpf
add a comment |
up vote
0
down vote
favorite
I have a resource that holds some icons made up of paths. Each icon in the resource is held within a canvas. An example is shown below.
<Canvas x:Key="Home_Icon" Width="41.5455" Height="33.2506">
<Path x:Name="Path1" Width="29.3385" Height="25.8615" Canvas.Left="6.0829" Canvas.Top="7.37233" Stretch="Fill" Fill="Red" Data="…"/>
<Path x:Name="Path2" Width="40.9841" Height="19.2586" Canvas.Left="0.262487" Canvas.Top="0.445261" Stretch="Fill" Fill="yellow" Data="…"/>
</Canvas>
The above resource is used in a ControlTemplate for a Button as shown below (the ViewBox loads the canvas from the resource).
<Style x:Key="button_home_style" TargetType="Button">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="Button">
<Border Padding="5,15" Background="{StaticResource background_color_light}">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="auto"/>
</Grid.RowDefinitions>
<Viewbox Child="{StaticResource Home_Icon}">
</Viewbox>
</Grid>
</Border>
<ControlTemplate.Triggers>
<Trigger Property="IsMouseOver" Value="True">
<Setter TargetName="Path1" Property="Fill" Value="{StaticResource foreground_color_highlight}"/>
<Setter TargetName="Path2" Property="Fill" Value="{StaticResource foreground_color_highlight}"/>
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
The problem
I want to be able to change the Fill colour property on Path1 and Path2 (these are the path data held within the canvas in the resource) when the IsMouseOver is triggered on the button but I am unsure how to locate these.
wpf
add a comment |
up vote
0
down vote
favorite
up vote
0
down vote
favorite
I have a resource that holds some icons made up of paths. Each icon in the resource is held within a canvas. An example is shown below.
<Canvas x:Key="Home_Icon" Width="41.5455" Height="33.2506">
<Path x:Name="Path1" Width="29.3385" Height="25.8615" Canvas.Left="6.0829" Canvas.Top="7.37233" Stretch="Fill" Fill="Red" Data="…"/>
<Path x:Name="Path2" Width="40.9841" Height="19.2586" Canvas.Left="0.262487" Canvas.Top="0.445261" Stretch="Fill" Fill="yellow" Data="…"/>
</Canvas>
The above resource is used in a ControlTemplate for a Button as shown below (the ViewBox loads the canvas from the resource).
<Style x:Key="button_home_style" TargetType="Button">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="Button">
<Border Padding="5,15" Background="{StaticResource background_color_light}">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="auto"/>
</Grid.RowDefinitions>
<Viewbox Child="{StaticResource Home_Icon}">
</Viewbox>
</Grid>
</Border>
<ControlTemplate.Triggers>
<Trigger Property="IsMouseOver" Value="True">
<Setter TargetName="Path1" Property="Fill" Value="{StaticResource foreground_color_highlight}"/>
<Setter TargetName="Path2" Property="Fill" Value="{StaticResource foreground_color_highlight}"/>
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
The problem
I want to be able to change the Fill colour property on Path1 and Path2 (these are the path data held within the canvas in the resource) when the IsMouseOver is triggered on the button but I am unsure how to locate these.
wpf
I have a resource that holds some icons made up of paths. Each icon in the resource is held within a canvas. An example is shown below.
<Canvas x:Key="Home_Icon" Width="41.5455" Height="33.2506">
<Path x:Name="Path1" Width="29.3385" Height="25.8615" Canvas.Left="6.0829" Canvas.Top="7.37233" Stretch="Fill" Fill="Red" Data="…"/>
<Path x:Name="Path2" Width="40.9841" Height="19.2586" Canvas.Left="0.262487" Canvas.Top="0.445261" Stretch="Fill" Fill="yellow" Data="…"/>
</Canvas>
The above resource is used in a ControlTemplate for a Button as shown below (the ViewBox loads the canvas from the resource).
<Style x:Key="button_home_style" TargetType="Button">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="Button">
<Border Padding="5,15" Background="{StaticResource background_color_light}">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="auto"/>
</Grid.RowDefinitions>
<Viewbox Child="{StaticResource Home_Icon}">
</Viewbox>
</Grid>
</Border>
<ControlTemplate.Triggers>
<Trigger Property="IsMouseOver" Value="True">
<Setter TargetName="Path1" Property="Fill" Value="{StaticResource foreground_color_highlight}"/>
<Setter TargetName="Path2" Property="Fill" Value="{StaticResource foreground_color_highlight}"/>
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
The problem
I want to be able to change the Fill colour property on Path1 and Path2 (these are the path data held within the canvas in the resource) when the IsMouseOver is triggered on the button but I am unsure how to locate these.
wpf
wpf
asked 15 hours ago
Scott
127116
127116
add a comment |
add a comment |
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53416253%2faccess-child-property-held-within-wpf-resource-from-a-buttons-controltemplate%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown