2015-08-24 3 views
0

Я написал следующий стиль:Изображение кнопки исчезающего

<Style TargetType="Button" x:Key="ImageButton"> 
    <Setter Property="Width" Value="{Binding ActualHeight, RelativeSource={RelativeSource Self}}"/> 
    <Setter Property="Padding" Value="0"/> 
    <Setter Property="Margin" Value="5 0 5 0"/> 
    <Setter Property="Background" Value="Transparent"/> 
    <Setter Property="BorderBrush" Value="Transparent"/> 
</Style> 
<Style TargetType="Button" x:Key="AddButton" BasedOn="{StaticResource ImageButton}"> 
    <Setter Property="Content"> 
     <Setter.Value> 
      <Image Source="/MyProject;component/Images/Icons/Add.png"/> 
     </Setter.Value> 
    </Setter> 
    <Setter Property="Command" Value="{Binding AddCommand}"/> 
</Style> 
<Style TargetType="Button" x:Key="DeleteButton" BasedOn="{StaticResource ImageButton}"> 
    <Setter Property="Content"> 
     <Setter.Value> 
      <Image Source="/MyProject;component/Images/Icons/Delete.png"/> 
     </Setter.Value> 
    </Setter> 
    <Setter Property="Command" Value="{Binding DeleteCommand}"/> 
</Style> 

И я применяю его через:

<Button Style="{StaticResource DeleteButton}" Grid.Row="0" Grid.Column="0"/> 
<Button Style="{StaticResource AddButton}" Grid.Row="0" Grid.Column="1"/> 

Все это происходит в TabControl с вкладками. После изменения с определенной вкладки на эту вкладку изображение исчезнет. Когда я перехожу с другой вкладки на эту вкладку, изображения не исчезают. У кого-нибудь есть идеи, почему это добавляет?

UPDATE - Решение:

<DataTemplate x:Key="AddTemplate"> 
    <Image Source="/MyProject;component/Images/Icons/Add.png"/> 
</DataTemplate> 
<Style TargetType="Button" x:Key="AddButton" BasedOn="{StaticResource ImageButton}"> 
    <Setter Property="ContentTemplate" Value="{StaticResource AddTemplate}"/> 
    <Setter Property="Command" Value="{Binding AddCommand}"/> 
</Style> 

ответ

1

Я ответил на подобный вопрос here. В вашем случае основная причина такая же, как в ссылочном вопросе.

Смежные вопросы