views:

29

answers:

1

Hi I created my control which looks like that

<UserControl BorderBrush="#A9C2DE" HorizontalAlignment="Left" x:Class="WPFDiagramDesignerControl.Components.UcWBSBlock"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Height="86" Width="151" >

<UserControl.Resources>
    <ResourceDictionary Source="Tooltip.xaml"/>
</UserControl.Resources>
    <Grid x:Name="MainGrid">

    <TextBox Name="txtBox"  Style="{StaticResource DefaultStyle}" >
    </TextBox>

</Grid>

I also have a file with style for tooltip "Tooltip.xaml" How can I use this style for entire UserControl? Usually I did this with that code

<TextBox ToolTip="{StaticResource tooltipname}"/>

But it was easy because file with style was in resource dictionary of control where I placed textbox. However I can't do sth like that

 <UserControl BorderBrush="#A9C2DE" HorizontalAlignment="Left" ToolTip="{StaticResource tooltipname"}/>

Because at this point my style isn't in resource dicionary yet. I was trying to use this syntax

<UserControl.ToolTip>  </UserControl.ToolTip>

but I don't konow how should I refer to static resource

Maybe it is lame question but I just don't konow how to do it :)

+1  A: 

One option is to just use DynamicResource instead of StaticResource to defer the lookup until runtime and then use the attribute syntax:

<UserControl ... ToolTip="{DynamicResource tooltipname}" ...

You can also write the StaticResourceExtension using element syntax so that you can write it after the Resources section:

<UserControl.Resources>
    <ResourceDictionary Source="Tooltip.xaml"/>
</UserControl.Resources>
<UserControl.ToolTip>
    <StaticResourceExtension ResourceKey="tooltipname"/>
</UserControl.ToolTip>
Quartermeister
Thanks a lot :) This works great
germancoder