【发布时间】:2015-09-24 10:52:59
【问题描述】:
我是 Windows 应用程序开发的新手,并试图实现如下所示的内容:
Tag no:1 Tag no:2 Tag no:3 //屏幕左端
标签号:4 标签号:5 ...等等。
有些是这样的:
我在 Windows 10 通用应用程序开发中这样做。
提前致谢。
我的 Xaml 代码:
<StackPanel Orientation="Horizontal">
<TextBlock Text="{x:Bind comment_tags}" />
</StackPanel>
我的 c# 代码:
public List<string> comments_tags = new List<string>();
public MainPage()
{
this.InitializeComponent();
for(int i =0; i < 20; i++)
{
comments_tags.Add("Tag no: " + i);
}
}
我尝试过的新方法:
public List<Border> comment_tags = new List<Border>();
for (int i = 0; i < 20; i++)
{
Border b_temp = new Border();
b_temp.CornerRadius = new CornerRadius(3);
b_temp.Background = new SolidColorBrush(Colors.Aqua);
TextBlock t = new TextBlock();
t.Text = "Tag no: " + i;
t.Foreground = new SolidColorBrush(Colors.Aqua)
b_temp.Child = t;
comments_tags.Add(b_temp);
}
【问题讨论】:
-
如果我们能够将其绑定到 xaml 控件“public List
cmets_tags = new List ();” -
?我没看懂这条评论?
-
希望你现在可以通过看到我的新方法得到它。非常感谢。
-
你试过我在下面的答案中发布的内容吗?
-
是的,我试过了。它没有将字符串绑定到文本块。它显示空样式框
标签: c# wpf xaml data-binding