2010-09-17 2 views
0

Я создаю шаблонный RadioButton во время выполнения. После инициализации шаблона RadioButton я установил свойство DataContext и Tag, а затем добавлю эту кнопку в StackPanel. Проблема в том, что привязка шаблона не работает. ниже - XAML и код позади. Все это работает, если я присваиваю значения этим свойствам в XAML. Есть идеи?TemplateBinding для динамических элементов управления

Код: TemplatedRadioButton commandButton = new TemplatedRadioButton(); commandButton.DataContext = "bla"; // Некоторый txt, который я буду. commandButton.Tag = MyImage; // Это ImageIcon, который я создаю во время выполнения. MyStackPanel.Children.Add (commandButton);

XAML:

ответ

0

Извините: Код: TemplatedRadioButton CommandButton = новый TemplatedRadioButton(); commandButton.DataContext = "bla"; // Некоторый txt, который я буду. commandButton.Tag = MyImage; // Это ImageIcon, который я создаю во время выполнения. MyStackPanel.Children.Add (commandButton);

XAML:

<Grid Margin="0 8 0 1"> 
    <Grid.RowDefinitions> 
    <RowDefinition Height="4*"/> 
    <RowDefinition Name="textheight" Height="2*"/> 
    </Grid.RowDefinitions> 
<ContentPresenter x:Name="Content" ContentSource="Tag" Margin=" 4 4 6 6" HorizontalAlignment="{Binding HorizontalContentAlignment, RelativeSource={RelativeSource AncestorType={x:Type ItemsControl}}}" RecognizesAccessKey="True" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" VerticalAlignment="{Binding VerticalContentAlignment, RelativeSource={RelativeSource AncestorType={x:Type ItemsControl}}}"/> 

    <TextBlock Name="caption" Text="{TemplateBinding DataContext}" FontSize="11" FontFamily="/Fonts/#Lucida Grande" Grid.Row="1" HorizontalAlignment="Center" VerticalAlignment="Bottom" Foreground="#FF313131" Margin="0 2 0 6"/> 
</Grid> 
</Border> 

Смежные вопросы