0

我需要以编程方式更改列表框中文本块的绑定属性路径有什么解决方案吗?属性路径应根据当天进行更改。例如,如果是星期一,那么 Text="{Binding SubjectLongNameMonday}",如果是星期二,那么 Text="{Binding SubjectLongNameTuesday}" 等等...

<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}"
        }
4

1 回答 1

0

一个简单的方法是通过 SetValue:

lbToday.SetValue(ListBox.ItemsSourceProperty, this);
于 2013-08-23T18:00:50.607 回答