Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
160
Dynamically setting the header icon on a dialog defined in a control template
posted

Hi,

We are trying to adapt the example from the feature browser to dynamically set the header icon. We currently have a resource dictionary with a control template that contains a data template and a dialog. How can we bind the image source to the TemplateBinding of the control template? Here is the template code thus far: As you can see we are trying to bind the image source in the datatemplate to the Tag property of the XamDialog which in turn is bound to the TemplateBinding Icon of the parent window.

    <ControlTemplate x:Key="NonSizeableDialogueTemplate" TargetType="{x:Type Window}">

        <ControlTemplate.Resources>
            <DataTemplate x:Key="HeaderIcon">
                <Grid>
                    <Image Source="{Binding Path=Tag}" Height="45" Width="45" />
                </Grid>
            </DataTemplate>
        </ControlTemplate.Resources>


        <ig:XamDialogWindow Name="DialogueWin" Tag="{TemplateBinding Icon}" HeaderIconTemplate="{StaticResource HeaderIcon}" Style="{DynamicResource DialogueBigHeaderStyle}" Header="{TemplateBinding Title}">
            <ContentPresenter Name="WindowContent" Content="{TemplateBinding Content}" Margin="15,15,15,10"/>
        </ig:XamDialogWindow>
    </ControlTemplate>

Any assistance will be greatly appreciated

Regards, Mark

Parents
No Data
Reply
  • 160
    posted

    Unlike us to ask before thinking it through but we were short on time. We found the solution and it is a matter of setting the image source to:

    Source="{Binding Path=Icon,RelativeSource={RelativeSource FindAncestor,AncestorType={x:Type Window}}}"

     

     

Children
No Data