以编程方式更改列表框中文本块的绑定属性路径-windows8应用程序
本文关键字:绑定 属性 路径 应用程序 -windows8 文本 方式更 编程 列表 中文 | 更新日期: 2023-09-27 18:26:30
我需要以编程方式更改列表框内文本块的绑定属性路径,有什么解决方案吗?属性路径应根据当天进行更改。例如,如果是周一,则Text="{Binding SubjectLongNameMonday}",如果是周二,则Text="{Binding SubjectLongName Tuesday}
<ListBox x:Name="lbToday" Loaded="lbToday_Loaded">
<ListBox.ItemTemplate>
<DataTemplate >
<Grid x:Name="gridTodayBtn" Tag="{Binding}" Tapped="gridTodayBtn_Tapped">
<TextBlock x:Name="tbTodaySubjectNameMonday" Text="{Binding SubjectLongNameMonday}"/>
</Grid>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
C#代码
if (DateTime.Today.DayOfWeek.ToString().Equals("Monday"))
{
Binding myBinding2 = new Binding();
myBinding2.Source = this;
myBinding2.Path = new PropertyPath("MyDatasTimetableMonday");
lbToday.SetBinding(ListBox.ItemsSourceProperty, myBinding2);
//here need change path in xaml of textblock tbTodaySubjectNameMonday Text="{Binding SubjectLongNameMonday}" to Text="{Binding SubjectLongNameTuesday}"
}
一个简单的方法是通过SetValue:
lbToday.SetValue(ListBox.ItemsSourceProperty, this);