GUI 要素のパラメーター化された構築は使用できますObjectDataProvider
が、動的パラメーター値は許可されませんItemsControl.ItemTemplate
。たとえば、項目固有のパラメーター値を渡すことが期待される場合、以下のデータ テンプレートを使用することはできません! ...
XAML:
<Window x:Class="LDAPAutocomplete.Window1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:LDAPAutocomplete"
xmlns:System="clr-namespace:System;assembly=mscorlib"
Title="Window1" Height="300" Width="300">
<Window.Resources>
<DataTemplate x:Key="MyContentTemplate">
<DataTemplate.Resources>
<ObjectDataProvider x:Key="MyUserControlProvider"
ObjectType="{x:Type local:MyButton}">
<ObjectDataProvider.ConstructorParameters>
<System:String>Test Me</System:String>
</ObjectDataProvider.ConstructorParameters>
</ObjectDataProvider>
</DataTemplate.Resources>
<ContentPresenter
Content="{Binding
Source={StaticResource MyUserControlProvider}}" />
</DataTemplate>
</Window.Resources>
<StackPanel>
<local:LDAPAutocompleteTextBox/>
<ContentControl
ContentTemplate="{StaticResource MyContentTemplate}"
Content="123"/>
</StackPanel>
</Window>
コードビハインド:
public class MyButton : Button
{
public MyButton(string content)
{
this.Content = content;
}
}