简体   繁体   中英

XAML Style tag - property of property

In my ResourceDictionary.xaml I have a <Style> for one of my view templates. Inside, I have set a tooltip in the following way:

<Setter Property="ToolTip">
        <Setter.Value>
            <templates:MyToolTipTemplate/>
        </Setter.Value>
    </Setter>

How can I access the Tooltip 's properties (I need to set StaysOpen )?

Probably this can give you a direction for what you actually need.
Assuming that templates:MyToolTipTemplate is related to View (eg its a Control):

<Setter Property="ToolTip">
    <Setter.Value>
        <ToolTip StaysOpen="{Binding SomeBoolProperty,ElementName=template}">
            <templates:MyToolTipTemplate x:Name="template"/>
        </ToolTip>
    </Setter.Value>
</Setter>

If templates:MyToolTipTemplate is a ViewModel entity, you can place a relevant binding in a corresponding DataTemplate:

<DataTemplate DataType="{x:Type templates:MyToolTipTemplate}">
    <ToolTip>
        <SomeControl SomeProperty="{Binding StaysOpen,
             RelativeSource={RelativeSource AncestorType=ToolTip}, Mode=OneWayToSource}"/>
    </ToolTip>
</DataTemplate>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM