2017-08-23 21 views
0

我们正在开发一个内部的Windows 10应用程序进行时间跟踪。我们并不是非常熟悉它,但几乎已经建成了。问题是我们如何改变GridView中单个选定项目的内容。更改XAML点击里面的绑定gridview

XAML代码

<Page 
    x:Class="xxxxx.AllJobs" 
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
    xmlns:local="using:xxxxx" 
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
    mc:Ignorable="d"> 

    <Grid x:Name="gridAllJobs" Background="White"> 
     <GridView x:Name="gridViewJobs" Margin="5,120,0,0" Grid.Column="1" Background="LightGray"> 
      <GridView.ItemTemplate> 
       <DataTemplate> 
        <StackPanel x:Name="JobPanel" Orientation="Vertical" Background="White" Margin="10,10,0,0" Tapped="JobPanel_Tapped"> 
         <local:DefaultContent/> 
        </StackPanel> 
       </DataTemplate> 
      </GridView.ItemTemplate> 
     </GridView> 
     <TextBlock HorizontalAlignment="Left" Margin="10,10,0,0" TextWrapping="Wrap" Text="Jobs" VerticalAlignment="Top" Height="63" Width="124" FontSize="48"/> 
     <TextBlock x:Name="lblTime" Margin="0,10,10,0" TextWrapping="Wrap" Text="8:00:00" FontSize="36" FontWeight="Bold" TextAlignment="Right" Padding="2,2,2,0" HorizontalAlignment="Right" VerticalAlignment="Top" Width="174" Height="50"/> 
     <TextBlock x:Name="txtEmployee" HorizontalAlignment="Right" Margin="0,67,10,0" TextWrapping="Wrap" Text="" VerticalAlignment="Top" Height="48" Width="223" FontSize="24" TextAlignment="Right" Padding="2"/> 
     <Image x:Name="imgClockOut" HorizontalAlignment="Right" Height="115" Margin="0,0,238,0" VerticalAlignment="Top" Width="115" Source="Assets/clockout.png" Tapped="imgClockOut_Tapped"/> 

    </Grid> 
</Page> 

当用户选择一个单独的工作,我们希望与其他资源来代替(或也许有更好的方法来做到这一点)。但只是为了那一份工作。

DefaultConent是一个用户控件

<UserControl 
    x:Class="xxxxx.DefaultContent" 
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
    xmlns:local="using:xxxxx" 
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
    mc:Ignorable="d" 
    d:DesignHeight="150" 
    d:DesignWidth="400"> 

     <StackPanel x:Name="OuterPanel" Orientation="Horizontal" Background="White" Margin="20,0,0,0"> 
      <StackPanel x:Name="LeftPanel" Margin="5" Width="225"> 
       <TextBlock x:Name="txtProdID" Text="{Binding ModuleID}" FontSize="24" FontWeight="Bold" Foreground="DarkBlue" Padding="2" FontFamily="Microsoft JhengHei"/> 
       <TextBlock x:Name="txtJobID" Text="{Binding JobID}" Padding="2" FontSize="10"/> 
       <TextBlock Text="{Binding ItemID}" Padding="2" FontWeight="Bold" FontFamily="Microsoft JhengHei" FontSize="20"/> 
       <TextBlock Text="{Binding ProductName}" Padding="2" FontSize="12" TextWrapping="WrapWholeWords"/> 
      </StackPanel> 
      <StackPanel x:Name="DividerPanel" Margin="0,10,0,10" Background="LightGray" Width="1"/> 
      <StackPanel x:Name="RightPanel" Orientation="Vertical" Width="95" Margin="20,5,20,10"> 
       <TextBlock Text="{Binding CalcQty}" TextAlignment="Right" Padding="2" FontSize="24"/> 
       <TextBlock Text="{Binding OprID}" TextAlignment="Right" VerticalAlignment="Bottom" Padding="2,38,2,2"/> 
      </StackPanel> 
     <StackPanel x:Name="JobStatus"> 
      <local:NotStarted/> 
     </StackPanel> 
    </StackPanel> 
</UserControl> 

我们要替换按钮的内容。我们完全接受任何想法。我们可能会做这个完全错误的。我相信这是简单的,我们无法找到答案。

在此先感谢。

更新。

我已经能够绑定一个新的属性点击。当我将此属性添加为文本块时,它会在点击上进行更新。然而,“二传手”似乎没有做任何事情。我的文字的价值发生了变化。但面板的属性没有改变。

<StackPanel x:Name="LeftPanel" Margin="5" Width="225"> 
           <TextBlock x:Name="txtProdID" Text="{Binding ModuleID}" FontSize="24" FontWeight="Bold" Foreground="DarkBlue" Padding="2" FontFamily="Microsoft JhengHei"/> 
           <TextBlock x:Name="txtJobID" Text="{Binding JobID}" Padding="2" FontSize="10"/> 
           <TextBlock Text="{Binding ItemID}" Padding="2" FontWeight="Bold" FontFamily="Microsoft JhengHei" FontSize="20"/> 
           <TextBlock Text="{Binding ProductName}" Padding="2" FontSize="12" TextWrapping="WrapWholeWords"/> 
           <TextBlock Text="{Binding IsClicked}" Padding="2" FontSize="12" TextWrapping="WrapWholeWords"/> 
          </StackPanel> 

          <StackPanel x:Name="DividerPanel" Margin="0,10,0,10" Background="LightGray" Width="1"/> 

          <StackPanel x:Name="RightPanel" Orientation="Vertical" Width="95" Margin="20,5,20,10"> 
           <TextBlock Text="{Binding CalcQty}" TextAlignment="Right" Padding="2" FontSize="24"/> 
           <TextBlock Text="{Binding OprID}" TextAlignment="Right" VerticalAlignment="Bottom" Padding="2,38,2,2"/> 
          </StackPanel> 

          <VisualStateManager.VisualStateGroups> 
           <VisualStateGroup> 
            <VisualState> 
             <VisualState.StateTriggers> 
              <StateTrigger x:Name="CurrItem" IsActive="{Binding Path=IsClicked}"/> 
             </VisualState.StateTriggers> 
             <VisualState.Setters> 
              <Setter Target="LeftPanel.Visibility" Value="Collapsed"/> 
             </VisualState.Setters> 
            </VisualState> 
           </VisualStateGroup> 
          </VisualStateManager.VisualStateGroups> 
         </StackPanel> 
+0

你见过任何关于制定者和触发器这样的:https://stackoverflow.com/a/45802145/6797752? – Denis

+0

我无法让它工作。 看起来总是如此。它会影响面板的每个实例。当我点击一个面板时没有任何变化。 –

+0

由于您的数据模板中已经有了一个usercontrol,因此可以封装其中的所有UI逻辑。我会创建两个内容,当点击/点击时只显示一个第一个和*翻转*。 –

回答

0

为什么你的用户界面没有更新的几​​个原因。

  1. 您可以将一种模式应用于您的绑定可能会强制数据返回。

  2. 但更重要的是,您是否实现了INotifyPropertyChanged接口,这允许更新的属性在更新时返回给UI。

要做到这一点的: INotifyPropertyChanged接口添加到您阶层的住房数据需要更新,那么它会提示你添加您的实现。

然后更新您的属性,以返回属性。

例子:

public class DemoCustomer : INotifyPropertyChanged 
     { 
    public event PropertyChangedEventHandler PropertyChanged; 

//NotifyPropertyChanged 

    // This method is called by the Set accessor of each property. 
      // The CallerMemberName attribute that is applied to the optional propertyName 
      // parameter causes the property name of the caller to be substituted as an argument. 
      private void NotifyPropertyChanged([CallerMemberName] String propertyName = "") 
      { 
       if (PropertyChanged != null) 
       { 
        PropertyChanged(this, new PropertyChangedEventArgs(propertyName)); 
       } 
      } 

    //Property: 

    public string CustomerName 
      { 
       get 
       { 
        return this.customerNameValue; 
       } 

       set 
       { 
        if (value != this.customerNameValue) 
        { 
         this.customerNameValue = value; 
         NotifyPropertyChanged(); 
        } 
       } 
      } 
    } 

引用例如:https://msdn.microsoft.com/en-us/library/system.componentmodel.inotifypropertychanged(v=vs.110).aspx