2012-03-28 3 views
0

안녕하세요 저는 핀 버튼을위한 일반적인 스타일을 만들고 싶습니다.핀 토글 버튼 스타일

<Window x:Class="TooglePinButtonStyle.MainWindow" 
     xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
     xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
     Title="MainWindow" Height="350" Width="525"> 
    <Window.Resources> 
    <Image x:Key="pinImage" 
      Width="14" 
      Height="14" 
      Source="/TooglePinButtonStyle;component/Images/pin.png" /> 
    <Image x:Key="unPinImage" 
      Width="14" 
      Height="14" 
      Source="/TooglePinButtonStyle;component/Images/unpin.png" /> 

    <Style x:Key="pinButtonStyle" 
      TargetType="{x:Type ToggleButton}"> 
     <Setter Property="Content" Value="{DynamicResource unPinImage}" /> 
     <Style.Triggers> 
     <Trigger Property="IsChecked" Value="True"> 
      <Setter Property="Content" Value="{DynamicResource pinImage}" /> 
     </Trigger> 
     </Style.Triggers> 
    </Style> 
    </Window.Resources> 
    <StackPanel> 
    <ToggleButton Height="30" 
        Width="30" 
        Style="{StaticResource pinButtonStyle}"/> 
    <ToggleButton Height="30" 
        Width="30" 
        Style="{StaticResource pinButtonStyle}"/> 
    </StackPanel> 
</Window> 

가 하나 개의 버튼을하지만 난 두 개의 버튼이 때 UI가

와 충돌 할 때 잘 작동 "지정된 요소가 이미 다른 요소의 논리적 자식입니다. 그것은 분리 첫번째."

예외.

답변

1

오히려 Content보다 non-shared 이미지를 만들거나 이미지 (안 화상에 대한 참조)를 포함 일부 DataTemplateContentTemplate 설정 하나. UI 요소의 인스턴스가 하나 뿐인 경우이 문제가 발생합니다. 템플릿은 인스턴스를 직접 사용하는 것보다 생성해야하는 것을 설명합니다.

+0

ResourceDictionary에 스타일을 추가하고 표시된 이미지의 x : Shared = "false" – Mohit