私は非常に混乱しています。いくつかの表示のためにバインドしているxmlファイルがあります。私の xml の 1 つのセクションは次のようになります。
<Section Name="Water Efficiency">
<Prerequisite Title="Prerequisite 1" Description="Water Use Reduction—20% Reduction " />
<Credit CanCheckFromModel="False" CheckFromModel="False" Title="Credit 1" Description="Water Efficient Landscaping" IsGoal="Yes" PossiblePoints="2 to 4">
<Option Description="Reduce by 50%" PossiblePoints="2" />
<Option Description="No Potable Water Use or Irrigation" PossiblePoints="4" />
</Credit>
<Credit CanCheckFromModel="False" CheckFromModel="False" Title="Credit 2" Description="Innovative Wastewater Technologies" IsGoal="Yes" PossiblePoints="2" />
<Credit CanCheckFromModel="True" CheckFromModel="True" Title="Credit 3" Description="Water Use Reduction " IsGoal="Yes" PossiblePoints="2 to 4">
<Option Description="Reduce by 30%" PossiblePoints="2" />
<Option Description="Reduce by 35%" PossiblePoints="3" />
<Option Description="Reduce by 40%" PossiblePoints="4" />
</Credit>
</Section>
基本的に、「オプション」のコンボボックスがあり、それをうまく入力できます。オプションがない場合は空白です。オプションがない場合は無効にしたいと思います。次のように変換コードを使用して、このためのコンバーターを作成しました。
//convert to an xmlnodelist
XmlNodeList s = value as XmlNodeList;
System.Diagnostics.Debugger.Break();
//make sure the conversion worked
if (s != null)
{
//see if there are any nodes in the list
if (s.Count != 0)
{
//has nodes, check to see if any of them are of type 'Option'
bool HasOptions = false;
foreach (XmlNode n in s)
{
if (n.Name == "Option")
{
//found one with an option, exit loop
HasOptions = true;
break;
}
}
//check if we found any options and return accordingly
return HasOptions;
}
}
//conversion failed or count was 0, false by default
return false;
コンボボックスの私の XAML マークアップは次のとおりです。
<ComboBox Width="200" DataContext="{Binding}" ItemsSource="{Binding XPath=./*}" IsEnabled="{Binding XPath=./*, Converter={StaticResource ConvOptions}}" >
<ComboBox.ItemTemplate>
<DataTemplate>
<TextBlock Text="{Binding XPath=@Description}" />
</DataTemplate>
</ComboBox.ItemTemplate>
</ComboBox>
私にとって本当に紛らわしい部分は、これが逆に機能することです。オプションのサブ項目を持つエントリは無効になり、そうでないエントリは有効になります。戻り値を切り替えるだけですべてが有効になるので、オプションのないものには触れないようです。コンバーターにブレークポイントを設定しようとしましたが、値に対して表示されるのは空の文字列だけです。
誰かがここで何が起こっているのか教えてもらえますか?