2011-06-21 24 views
0

私のカスタムICalendarItemインターフェイスを実装するクラスが4つあります。 そのインターフェイスには「Jours」というプロパティがあります。DataTriggerをInterfaceプロパティにバインドする方法

ObservableCollection<KeyValuePair<DateTime, DateTime>> Jours; 

このような私のクラスのオーバーライド、そのプロパティ:Jours.Countが0から1になると

public override ObservableCollection<KeyValuePair<DateTime, DateTime>> Jours {...} 

、私はアクションをトリガーにしたいので、私はこの試みた:

<DataTrigger Binding="{Binding Path=Jours.Count}" Value="1"> 

<DataTrigger Binding="{Binding Path=(ICalendarItem)Jours.Count}" Value="1"> 

これらの2つのDataTriggerは動作しません。

誰かがDataTriggerをInterfaceプロパティにバインドする方法を知っていますか?

答えて

2

、あなたは括弧内の所定の位置に、名前空間、インターフェイスおよびプロパティ名を配置する必要があります。括弧の外側にあるCountのようなサブプロパティを参照することができます。私dictionnaryの上部にあると=(IFSこの

<DataTrigger Binding="{Binding Path=(local:ICalendarItem.Jours).Count}" Value="1"> 
... 
</DataTrigger> 
+1

.Jours).Count} "Value =" 1 ">それがうまくいった! – Gab

+0

正しいですが、私は自分の答えに名前空間を指定する方法を指定する必要がありましたが、うれしく思いました – sellmeadog

1

私のテストでは、その作業はうまくいっています。おそらくあなたに役立つ次のコードを参照してください。

このコードは、 `Jours.Count 'が「3」に等しいとき、ウィンドウの背景が赤色になります。 XAML:

<Window x:Class="WpfApplication1.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> 
     <Style TargetType="Grid"> 
      <Style.Triggers> 
       <DataTrigger Binding="{Binding Jours.Count}" Value="3"> 
        <Setter Property="Control.Background" Value="Red" /> 
       </DataTrigger> 
      </Style.Triggers> 
     </Style> 
    </Window.Resources> 
    <Grid> 
    </Grid> 
</Window> 

分離コード:あなたは、具体的カスタムインターフェイスプロパティにバインドしたい場合は

public partial class MainWindow : Window 
{ 
    public MainWindow() 
    { 
     InitializeComponent(); 
     ITest test = new TestClass(); 
     this.DataContext = test; 
    } 
} 

interface ITest 
{ 
    ObservableCollection<KeyValuePair<DateTime, DateTime>> Jours { get; set; } 
} 

class TestClass : ITest 
{ 
    public TestClass() 
    { 
     Jours = new ObservableCollection<KeyValuePair<DateTime, DateTime>>(); 
     Jours.Add(new KeyValuePair<DateTime, DateTime>(DateTime.Now, DateTime.Now)); 
     Jours.Add(new KeyValuePair<DateTime, DateTime>(DateTime.Now, DateTime.Now)); 
     Jours.Add(new KeyValuePair<DateTime, DateTime>(DateTime.Now, DateTime.Now)); 
    } 

    public ObservableCollection<KeyValuePair<DateTime, DateTime>> Jours { get; set; } 
} 
関連する問題