locked
Cannot Bind ContentControl.Content to static resource

    Question

  • Why is this not working:

    <Page.Resources>
        <Style x:Key="ButtonStyle1" TargetType="Button">
             <Setter Property="Background" Value="{ThemeResource ButtonBackgroundThemeBrush}"/>
             <Setter Property="Foreground" Value="{ThemeResource ButtonForegroundThemeBrush}"/>
              <Setter Property="BorderBrush" Value="{ThemeResource ButtonBorderThemeBrush}"/>
              <Setter Property="BorderThickness" Value="{ThemeResource ButtonBorderThemeThickness}"/>
              <Setter Property="Padding" Value="12,4,12,4"/>
              <Setter Property="HorizontalAlignment" Value="Left"/>
              <Setter Property="VerticalAlignment" Value="Center"/>
              <Setter Property="FontFamily" Value="{ThemeResource ContentControlThemeFontFamily}"/>
              <Setter Property="FontWeight" Value="SemiBold"/>
              <Setter Property="FontSize" Value="{ThemeResource ControlContentThemeFontSize}"/>
               <Setter Property="Template">
                   <Setter.Value>
                     <ControlTemplate TargetType="Button">
                            <Grid>
                             <VisualStateManager.VisualStateGroups>
                                    <VisualStateGroup x:Name="CommonStates">
                                        <VisualState x:Name="Normal"/>
                                        <VisualState x:Name="PointerOver">
                                            <Storyboard>
                                                <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="Foreground" Storyboard.TargetName="ContentPresenter">
                                                    <DiscreteObjectKeyFrame KeyTime="0" Value="{ThemeResource ButtonPointerOverForegroundThemeBrush}"/>
                                                </ObjectAnimationUsingKeyFrames>
                                            </Storyboard>
                                        </VisualState>
                                        <VisualState x:Name="Pressed">
                                            <Storyboard>
                                                <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="Foreground" Storyboard.TargetName="ContentPresenter">
                                                    <DiscreteObjectKeyFrame KeyTime="0" Value="{ThemeResource ButtonPressedForegroundThemeBrush}"/>
                                                </ObjectAnimationUsingKeyFrames>
                                            </Storyboard>
                                        </VisualState>
                                        <VisualState x:Name="Disabled">
                                            <Storyboard>
                                                <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="Foreground" Storyboard.TargetName="ContentPresenter">
                                                    <DiscreteObjectKeyFrame KeyTime="0" Value="{ThemeResource ButtonDisabledForegroundThemeBrush}"/>
                                                </ObjectAnimationUsingKeyFrames>
                                            </Storyboard>
                                        </VisualState>
                                    </VisualStateGroup>
                                    <VisualStateGroup x:Name="FocusStates">
                                        <VisualState x:Name="Focused">
                                            <Storyboard>
                                                <DoubleAnimation Duration="0" To="1" Storyboard.TargetProperty="Opacity" Storyboard.TargetName="FocusVisualWhite"/>
                                                <DoubleAnimation Duration="0" To="1" Storyboard.TargetProperty="Opacity" Storyboard.TargetName="FocusVisualBlack"/>
                                            </Storyboard>
                                        </VisualState>
                                        <VisualState x:Name="Unfocused"/>
                                        <VisualState x:Name="PointerFocused"/>
                                    </VisualStateGroup>
                                </VisualStateManager.VisualStateGroups>
                                <Rectangle x:Name="FocusVisualWhite" IsHitTestVisible="False" Opacity="0" StrokeDashOffset="1.5" StrokeEndLineCap="Square" Stroke="{ThemeResource FocusVisualWhiteStrokeThemeBrush}" StrokeDashArray="1,1"/>
                                <Rectangle x:Name="FocusVisualBlack" IsHitTestVisible="False" Opacity="0" StrokeDashOffset="0.5" StrokeEndLineCap="Square" Stroke="{ThemeResource FocusVisualBlackStrokeThemeBrush}" StrokeDashArray="1,1"/>
                                <ContentPresenter x:Name="ContentPresenter" AutomationProperties.AccessibilityView="Raw" ContentTemplate="{TemplateBinding ContentTemplate}" ContentTransitions="{TemplateBinding ContentTransitions}" Content="{TemplateBinding Content}" HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" Margin="61,72,66,77" VerticalAlignment="{TemplateBinding VerticalContentAlignment}"/>
                                <ContentControl Content="{StaticResource facebookLogin}" HorizontalAlignment="Left" VerticalAlignment="Top"/>
                            </Grid>
                        </ControlTemplate>
                    </Setter.Value>
                </Setter>
            </Style>
        </Page.Resources>

    That is my control template.

            <ResourceDictionary>
                <Viewbox x:Key="facebookLogin" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
                    <Grid>
                        <Grid Name="backgroundGrid" Width="48" Height="48" Visibility="Visible">
                            <Rectangle Fill="#FF000000" Name="Rect" Visibility="Visible" />
                        </Grid>
                        <Path Data="F1M-1775.32,-68.9708L-1831.47,-68.9708C-1833.27,-68.9708,-1834.73,-67.3745,-1834.73,-65.4058L-1834.73,-10.1649C-1834.73,-8.19482,-1833.27,-6.59973,-1831.47,-6.59973L-1802.47,-6.59973 -1802.47,-32.2261 -1809.5,-32.2261 -1809.5,-40.5503 -1802.47,-40.5503 -1802.47,-45.5282C-1802.47,-50.9435,-1798.08,-55.3315,-1792.66,-55.3315L-1783.74,-55.3315 -1783.74,-47.0099 -1787.86,-47.0099C-1789.89,-47.0099,-1791.53,-45.3667,-1791.53,-43.3407L-1791.53,-40.5503 -1783.74,-40.5503 -1783.74,-32.2261 -1791.53,-32.2261 -1791.53,-6.59973 -1775.32,-6.59973C-1773.52,-6.59973,-1772.06,-8.19482,-1772.06,-10.1649L-1772.06,-65.4058C-1772.06,-67.3745,-1773.52,-68.9708,-1775.32,-68.9708" Stretch="Uniform" Fill="#FFFFFFFF" Width="26" Height="26" Margin="0,0,0,0" RenderTransformOrigin="0.5,0.5">
                            <Path.RenderTransform>
                                <TransformGroup>
                                    <TransformGroup.Children>
                                        <RotateTransform Angle="0" />
                                        <ScaleTransform ScaleX="1" ScaleY="1" />
                                    </TransformGroup.Children>
                                </TransformGroup>
                            </Path.RenderTransform>
                        </Path>
                    </Grid>
                </Viewbox>
    
            </ResourceDictionary>
    

    That is the resource that I am trying to set the content property of the content control to.

    I am getting a Xaml Parse Exception that says it failed to set the property.


    James Mason Pack

    Monday, June 23, 2014 3:27 AM

All replies

  • Can you post a sample to OneDrive that will reproduce the issue?

    Matt Small - Microsoft Escalation Engineer - Forum Moderator
    If my reply answers your question, please mark this post as answered.

    NOTE: If I ask for code, please provide something that I can drop directly into a project and run (including XAML), or an actual application project. I'm trying to help a lot of people, so I don't have time to figure out weird snippets with undefined objects and unknown namespaces.

    Monday, June 23, 2014 1:54 PM
    Moderator
  • Sure will have it there with in the hour.

    James Mason Pack

    Monday, June 23, 2014 9:25 PM
  • Here is the link:

    http://1drv.ms/1j8DjkA


    James Mason Pack

    Monday, June 23, 2014 9:41 PM
  • The code that you are showing above isn't actually part of the project... I don't see it anywhere. Am I missing something?

    Matt Small - Microsoft Escalation Engineer - Forum Moderator
    If my reply answers your question, please mark this post as answered.

    NOTE: If I ask for code, please provide something that I can drop directly into a project and run (including XAML), or an actual application project. I'm trying to help a lot of people, so I don't have time to figure out weird snippets with undefined objects and unknown namespaces.

    Tuesday, June 24, 2014 2:39 PM
    Moderator
  • Matt,

    No your are not missing it. I did not put it in the project. The code above is the result of me customizing the default control template of a button. Which yields the same result as the code in the project. Sorry I assumed that would be ok and that was the fastest way to get a working sample up on OneDrive.

    Would you like for me to put the code from above in the project? I did not think there would be much of a difference.

    Thanks.


    James Mason Pack

    Tuesday, June 24, 2014 3:01 PM
  • No, I understand now. I'm investigating.

    Matt Small - Microsoft Escalation Engineer - Forum Moderator
    If my reply answers your question, please mark this post as answered.

    NOTE: If I ask for code, please provide something that I can drop directly into a project and run (including XAML), or an actual application project. I'm trying to help a lot of people, so I don't have time to figure out weird snippets with undefined objects and unknown namespaces.

    Tuesday, June 24, 2014 4:54 PM
    Moderator
  • Were you able to find anything out for me yet?

    Just wondering. I know you are probably very busy.


    James Mason Pack

    Saturday, July 5, 2014 3:42 AM