2012-05-29 42 views
0

我正在WPF上工作,並且對XAML自定義創建的控件知之甚少。 我有一個自定義控制名「DualButton」如下:重寫IsEnabled屬性的自定義控件DualButton設置可見性

<Controls:DualButton x:Name="StandardConferenceCancelButton" 
              Width="90" 
              Height="25" 
              Margin="2" 
              LeftButtonCommand="{Binding StandardModeConnectCommand}" 
              RightButtonCommand="{Binding ConferenceCancelCommand}" 
              > 
          <AccessText HorizontalAlignment="Center" Text="{x:Static I18N:TelephonyRegionViewRes.Standard}" /> 
         </Controls:DualButton> 

其2扶養屬性「LeftButtonCommand」和「RightButtonCommand'binds兩個不同個ICommand。 我想將此按鈕的可見性設置爲LeftButtonCommand的CanExecute,以便當LeftButtonCommandCanExecute()返回true時,該時間只有按鈕可見。 我把dependancyProperty「的IsEnabled」我需要什麼進一步在這個

+0

如果LeftButtonDownCommand的CanExecute方法返回false,您的按鈕是否被禁用? –

+0

不是。這就是我想要的。如果需要,我可以發佈用於'DualButton'的模板。 – deathrace

+0

是的,請張貼模板。問題的癥結可能在那裏。 – XAMeLi

回答

1

我知道這是來不及做,但可能幫助別人......

  1. 在你的DataContext,創建一個屬性一樣IsVisible返回

    StandardModeConnectCommand.CanExecute() 
    
  2. 在你的窗口或用戶控件添加資源

    <Window.Resources> 
        <BooleanToVisibilityConverter x:Key="BooleanToVisibilityConverter"/> 
        </Window.Resources> 
    
  3. 在你的雙按鈕,之後或命令之前,添加:

    Visibility="{Binding IsVisible, Converter={StaticResource BooleanToVisibilityConverter}}" 
    
  4. 最後,在地方CanEecute的返回值可能會發生改變,加在你的DataContext一個

    NotifyPropertyChanged(nameof(IsVIsible)); 
    

你應該跟着這個。