2017-08-23 20 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