ListView内の複数の列に対してDataTemplateを再利用したい。与えられた2つのXmlDataProvider
は、最初の項目で選択した項目を使用して2番目の値から値を選択します。 DataTemplate
に追加リソースを指定すると、これが機能します。しかし、これは私にDataTemplateのコードを複製させ、追加のリソースを交換するように強制します。 私は何をしたいのはこれです:XAMLコードの上に次のエラーが仕事と生成しないこと複数のリソースをDataTemplateに渡すことはできますか?
public class MultiXmlConverter : IMultiValueConverter
{
public object Convert(object[] value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
var element = value[0] as XmlElement;
var dataProvider = value[1] as XmlDataProvider;
XmlNodeList nodes = dataProvider.Document.SelectNodes("/Items/Item/[@id='" + element.Attributes["id"].Value.ToString() + "']");
return nodes[0].Attributes["Text"].Value.ToString();
}
public object[] ConvertBack(object value, Type[] targetType, object parameter, System.Globalization.CultureInfo culture)
{
throw new Exception("The method or operation is not implemented.");
}
}
注:ここでは、完全(および参照)のために
<Window x:Class="LayoutTests.Window2"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:LayoutTests"
Title="Window2" Height="300" Width="300">
<Window.Resources>
<XmlDataProvider x:Key="XmlDataA" IsInitialLoadEnabled="True">
<x:XData>
<Items xmlns="">
<Item id="1" text="A:1"/>
<Item id="2" text="A:2"/>
<Item id="3" text="A:3"/>
</Items>
</x:XData>
</XmlDataProvider>
<XmlDataProvider x:Key="XmlDataB" IsInitialLoadEnabled="True">
<x:XData>
<Items xmlns="">
<Item id="1" text="B:1"/>
<Item id="2" text="B:2"/>
<Item id="3" text="B:3"/>
</Items>
</x:XData>
</XmlDataProvider>
<local:MultiXmlConverter x:Key="MultiXmlConverter"/>
<local:DatabindingDebugConverter x:Key="DatabindingDebugConverter"/>
<DataTemplate x:Key="Template" >
<TextBlock Text="{Binding Converter={StaticResource MultiXmlConverter}}"/>
</DataTemplate>
</Window.Resources>
<Grid>
<ListView ItemsSource="{Binding Source={StaticResource XmlDataA}, XPath='/Items/Item'}" Background="Transparent">
<ListView.View>
<GridView>
<GridViewColumn CellTemplate="{StaticResource Template}">
<GridViewColumn.DisplayMemberBinding>
<MultiBinding>
<Binding Path="/"/>
<Binding Source="{StaticResource XmlDataB}"/>
</MultiBinding>
</GridViewColumn.DisplayMemberBinding>
</GridViewColumn>
</GridView>
</ListView.View>
</ListView>
</Grid>
</Window>
が可能コンバータです。 "MultiValueConverterを指定する必要があるため、MultiBindingを設定できません。" MultiBinding
は、私がやりたいことの単なるプレースホルダーです。研究は、DataTemplate
に追加のパラメータを渡す可能性を明らかにしていませんでした - しかし、私はそれほど有用な何かがどこかに隠されていないと信じていません。
の横にあるDataTemplate
に追加リソースを渡すにはどうすればよいですか?
何らかの関連する質問はhttp://stackoverflow.com/questions/8328443/generic-datatemplate-used-in-multiple-gridviewcolumnsです。 – Pascal