views:

26

answers:

0

Hello,

i have created a UserControl to make a ImageButton. But i replaced the the UserControl Item with a Button.

< Button x:Class="myimagebutton" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:local="clr-namespace:imagebutton">

<Grid x:Name="grdButton">
    <Grid.ColumnDefinitions>
        <ColumnDefinition />
        <ColumnDefinition />
    </Grid.ColumnDefinitions>

    <Image Grid.Column="0" 
           x:Name="btnImage"
           HorizontalAlignment="Left" VerticalAlignment="Center">
    </Image>
    <TextBlock Grid.Column="1"
               TextWrapping="Wrap"
               Text="{Binding Text}" VerticalAlignment="Center" Margin="2 0 2 0"/>
</Grid>

< /Button>

now i want to apply the Toolbar Button Style to my Button if this Button is in a Toolbar. I have read this article link text and put this

If Me.Style Is Nothing AndAlso TypeOf Me.Parent Is ToolBar Then
   Me.Style = DirectCast(FindResource(ToolBar.ButtonStyleKey), Style)
End If

in my Codebehind.

After that i put my Button in a Toolbar and another out of the Toolbar to test it. But the Button always get the default style. After debuging i find out that Me.Parent is always Nothing. So now is my question how i get the information that my button is in a toolbar or not?