2013-12-10 5 views
0

IsEnabled 속성을 false로 설정하는 쉬운 방법은 없습니까? 단추를 클릭 한 후 CheckBox 컨트롤을 클릭합니다. 버튼이 다른 xaml 파일에 있음을 확인하십시오. 코드없이 xaml에서만 할 수 있습니까?usercontrol에있는 다른 컨트롤의 작업을 기반으로 CheckBox 컨트롤의 isEnabled 속성을 설정합니다.

MainWindow.xaml

<Window 
     xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
     xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
     xmlns:local="clr-namespace:WpfApplication1" x:Class="WpfApplication1.MainWindow" 
     Title="MainWindow" Height="350" Width="525"> 
    <Grid> 
     <Grid.RowDefinitions> 
      <RowDefinition Height="Auto"/> 
      <RowDefinition Height="*"/> 
     </Grid.RowDefinitions> 
     <CheckBox Grid.Row="0" Content="CheckBox" HorizontalAlignment="Left" VerticalAlignment="Top"/> 
     <local:UserControl1 HorizontalAlignment="Left" Margin="31,54,0,0" Grid.Row="1" VerticalAlignment="Top"/> 
    </Grid> 
</Window> 

UserControl1.xaml

<UserControl x:Class="WpfApplication1.UserControl1" 
      xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
      xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
      xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
      xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
      mc:Ignorable="d" 
    > 
    <Grid> 
     <Button Content="Button" HorizontalAlignment="Left" Width="75"/> 
    </Grid> 
</UserControl> 

+0

코드 숨김 또는보기 모드에서 코드를 사용해야합니다. afmA XAML에서이를 수행 할 방법이 없습니다. – JMK

답변

0

당신은 bool 속성을 추가해야하고, 대신 ToggleButton를 사용합니다 Button. 여기서 우리는 bool IsDefault 재산 (당신이 좋아하는 무엇을 호출)에 CheckBox.IsChecked 속성을 결합하고 UserControl.DataContext 속성을 설정 : 이제

<UserControl x:Class="WpfApplication1.UserControl1" 
      xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
      xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
      xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
      xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
      mc:Ignorable="d"> 
    <Grid> 
     <ToggleButton Content="Button" IsChecked="{Binding IsDefault}" 
HorizontalAlignment="Left" Width="75" /> 
    </Grid> 
</UserControl> 

: 우리는 bool IsDefault 속성에 ToggleButton.IsChecked 속성을 결합 여기

<Window x:Class="WpfApplication1.MainWindow" 
     xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
     xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
     xmlns:local="clr-namespace:WpfApplication1" 
     Title="MainWindow" Height="350" Width="525"> 
    <Grid> 
     <Grid.RowDefinitions> 
      <RowDefinition Height="Auto"/> 
      <RowDefinition Height="*"/> 
     </Grid.RowDefinitions> 
     <CheckBox Grid.Row="0" Content="CheckBox" IsChecked="{Binding IsDefault}" 
HorizontalAlignment="Left" VerticalAlignment="Top"/> 
     <local:UserControl1 DataContext="{Binding}" HorizontalAlignment="Left" 
Margin="31,54,0,0" Grid.Row="1" VerticalAlignment="Top"/> 
    </Grid> 
</Window> 

을 그들은 데이터 바운드이며, 하나를 변경하면 다른 하나가 업데이트됩니다.

관련 문제