在数据模板内按钮单击设置进度条可见性

时间:2015-07-16 11:01:26

标签: c# xaml windows-phone-8

我正在尝试在按钮单击中设置进度条visibilty,其中两者都在数据模板中。我无法设置进度条的名称并发送可见性,因为它位于模板中。

有没有任何方法可以实现这一目标。以下代码是我尝试过的。

<DataTemplate>
     <Grid>
          <Button Click="Image_Download" Loaded="Button_Loaded" Tag="{Binding .}" Width="80" Height="80" >
              <Button.Template>
                    <ControlTemplate TargetType="Button">
                         <Border HorizontalAlignment="Center" VerticalAlignment="Center" >
                                <ContentControl Content="{TemplateBinding Content}"/>
                         </Border>
                    </ControlTemplate>
          </Button.Template>
              <Image Source="c_image.png"  Tag="{Binding .}" />
          </Button>
          <ProgressBar VerticalAlignment="Bottom" IsIndeterminate="true" Visibility="Collapsed" Style="{StaticResource CustomIndeterminateProgressBar}" />
     </Grid>
</DataTemplate>

1 个答案:

答案 0 :(得分:0)

你可以这样做

private void Image_Download(object sender, RoutedEventArgs e) {
    Button button = sender as Button;
    if (button != null) {
        Grid grid = button.Parent as Grid;
        if (grid != null) {
            ProgressBar progressBar = grid.Children.OfType<ProgressBar>().FirstOrDefault();
            if (progressBar != null) {
                progressBar.Visibility = Visibility.Hidden;
            }
        }
    }
}