首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >动态控件的TemplateBinding

动态控件的TemplateBinding
EN

Stack Overflow用户
提问于 2010-09-18 05:38:01
回答 1查看 156关注 0票数 0

我在运行时创建一个模板化的RadioButton。在初始化模板化的RadioButton之后,我设置了DataContext和Tag属性,然后将此按钮添加到StackPanel中。问题是模板绑定不起作用。下面是XAML和后面的代码。如果我在XAML中为这些属性赋值,所有这些都会起作用。有什么想法吗?

代码: TemplatedRadioButton commandButton = new TemplatedRadioButton();commandButton.DataContext = "bla";//我将使用一些txt。commandButton.Tag = MyImage;//这也是我在运行时创建的ImageIcon。MyStackPanel.Children.Add(commandButton);

XAML:

EN

回答 1

Stack Overflow用户

发布于 2010-09-18 05:43:31

抱歉:代码: TemplatedRadioButton commandButton = new TemplatedRadioButton();commandButton.DataContext = "bla";//我将使用一些txt。commandButton.Tag = MyImage;//这也是我在运行时创建的ImageIcon。MyStackPanel.Children.Add(commandButton);

XAML:

代码语言:javascript
复制
 <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>
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/3739234

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档