2017-08-23 4 views
0

Nous développons actuellement une application Windows 10 interne pour le suivi du temps. Nous ne le connaissons pas très bien, mais nous l'avons presque construit. La question est de savoir comment changer le contenu d'un seul élément sélectionné dans une grille.Modifier le code XAML à l'intérieur d'un affichage en grille lié

code 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> 

Lorsque l'utilisateur sélectionne un travail individuel, nous voulons que l'être remplacée par une autre ressource (ou peut-être il y a une meilleure façon de le faire). Mais juste pour ce travail.

DefaultConent est un usercontrol

<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> 

Et nous voulons remplacer ce contenu avec des boutons. Nous sommes complètement ouverts à toutes les idées. Nous pouvons aller à ce sujet complètement faux. Je suis sûr que c'est quelque chose de simple et nous ne pouvons pas trouver la réponse.

Merci d'avance.

Mise à jour.

J'ai été capable de lier une nouvelle propriété sur click. Lorsque j'ajoute cette propriété en tant que bloc de texte, elle se met à jour lors du clic. Cependant, le "Setter" ne semble pas faire quoi que ce soit. La valeur de mon texte change. Mais les propriétés du panneau ne changent pas.

<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

Avez-vous vu quelque chose sur setters et déclenche comme ceci: https://stackoverflow.com/a/45802145/6797752? – Denis

+0

Je n'arrive pas à faire marcher ça. Semble être toujours vrai. Et cela affecte chaque instance du panneau. Rien ne change lorsque je clique sur un seul panneau. –

+0

Étant donné que vous disposez déjà d'un contrôle utilisateur dans votre modèle de données, vous pouvez encapsuler toute la logique de l'interface utilisateur. Je créerais deux contenus, révélerait seulement un premier et * flip * à l'autre quand on cliquait/tapait. –

Répondre

0

Plusieurs raisons pour lesquelles votre interface utilisateur ne se met pas à jour.

  1. Vous pouvez appliquer un mode à votre liaison peut forcer les données en arrière. Mais, plus important encore, implémentez-vous l'interface INotifyPropertyChanged, ce qui permet à la propriété mise à jour d'être renvoyée à l'interface utilisateur lors de sa mise à jour.

Pour ce faire, ajoutez l'interface de : INotifyPropertyChanged à votre logement de classe vos données qui doit être mis à jour, il vous demandera pour vous d'ajouter votre implémentation. Ensuite, mettez à jour vos propriétés pour que la propriété revienne à zéro.

Exemple:

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(); 
        } 
       } 
      } 
    } 

exemple de Referenced: https://msdn.microsoft.com/en-us/library/system.componentmodel.inotifypropertychanged(v=vs.110).aspx