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.










share|improve this question


























    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.










    share|improve this question
























      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.










      share|improve this question













      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






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked 15 hours ago









      Scott

      127116




      127116





























          active

          oldest

          votes











          Your Answer






          StackExchange.ifUsing("editor", function () {
          StackExchange.using("externalEditor", function () {
          StackExchange.using("snippets", function () {
          StackExchange.snippets.init();
          });
          });
          }, "code-snippets");

          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "1"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });














           

          draft saved


          draft discarded


















          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






























          active

          oldest

          votes













          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes
















           

          draft saved


          draft discarded



















































           


          draft saved


          draft discarded














          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





















































          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







          Popular posts from this blog

          What visual should I use to simply compare current year value vs last year in Power BI desktop

          How to ignore python UserWarning in pytest?

          Alexandru Averescu