简体   繁体   English

如何更新WP8应用程序中的复选框

[英]How to update the checkbox in wp8 app

In my wp8 app, I have check box which is under a listbox. 在我的wp8应用程序中,我有一个复选框位于列表框下方。

Here is the XAML code: 这是XAML代码:

 <ListBox Name="URLListBox"  Grid.Row="2"  >
            <ListBox.ItemTemplate>
                <DataTemplate>
                    <Grid   >
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition/>
                            <ColumnDefinition Width="400"/>

                        </Grid.ColumnDefinitions>

                            <TextBlock   Grid.Column="1" Tag="{Binding b1Tag}" Tap="surenameTap"   x:Name="surename" FontFamily="Consolas"  FontSize="25" Text="{Binding text}"   VerticalAlignment="Center" HorizontalAlignment="Center" Margin="60,0,0,0"/>


                        <CheckBox IsEnabled="False"  BorderThickness="0" BorderBrush="DarkGreen"  Background="DarkGreen"  Grid.Column="0" x:Name="checkbox" IsChecked="{Binding file}"   ></CheckBox>

                    </Grid>
                </DataTemplate>
            </ListBox.ItemTemplate>
        </ListBox>

I want to update the checkbox while program is working. 我想在程序运行时更新复选框。 The checkbox shows if the data is downloaded or not. 复选框显示是否下载了数据。

I use BackgroundTransferRequest to download the file. 我使用BackgroundTransferRequest下载文件。 I want the checkbox to be checked when download is finished. 我希望下载完成后选中该复选框。

Actually I have class that determines which files are downloaded and I bind it with the checkbox, but it changes the checkbox when I enter the page. 实际上,我具有确定下载哪些文件的类,并将其与复选框绑定,但是当我进入页面时它将更改复选框。 That is I should go to previous menu and restart the page that contains checkboxes, then it shows which checkboxes are checked, but I want that when I am in page. 也就是说,我应该转到上一个菜单,然后重新启动包含复选框的页面,然后显示选中了哪些复选框,但是当我进入页面时,我希望这样做。

Here is the class that binds the checkbox: 这是绑定复选框的类:

lnk = new linkname();
URLListBox.ItemsSource = lnk.obj();

Make sure that you have set the DataContext and Implemented InotifyPropertyChanged Interface, Only when You implement the interface the property will get updated. 确保已设置DataContext和Implemented InotifyPropertyChanged接口,只有在实现接口后,属性才会更新。

And also you have to add Mode="TwoWay" when binding, something like this 而且还必须在绑定时添加Mode =“ TwoWay”,类似这样

IsChecked="{Binding file, Mode="TwoWay"}"

A quick sample is here 快速样品在这里

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM