2014-02-21 59 views
2

如何動態地設置樣式靜態資源從數據綁定如何定式的StaticResource 8

我是使用下面的代碼來改變每個網格的風格

<Grid HorizontalAlignment="Left" Width="453" Background="{StaticResource {Binding mystatus}}" > 

整個是

<phone:LongListSelector x:Name="MainLongListSelector" Margin="5,5" ItemsSource="{Binding TaskList}" SelectionChanged="MainLongListSelector_SelectionChanged" Foreground="Black" Height="654"> 
       <phone:LongListSelector.ItemTemplate> 
        <DataTemplate> 
         <Border Style="{StaticResource bordercss}" > 
          <Grid HorizontalAlignment="Left" Width="453" UseOptimizedManipulationRouting="True" Background="{StaticResource {Binding mystatus}}" > 
           <Grid.ColumnDefinitions> 
            <ColumnDefinition/> 
            <ColumnDefinition Width="5*"/> 
            <ColumnDefinition Width="6*" /> 
           </Grid.ColumnDefinitions> 
           <Grid.RowDefinitions> 
            <RowDefinition></RowDefinition> 
            <RowDefinition></RowDefinition> 
            <RowDefinition></RowDefinition> 
            <RowDefinition></RowDefinition> 
            <RowDefinition></RowDefinition> 
           </Grid.RowDefinitions> 
           <TextBlock Grid.Row="0" Grid.Column="0" Margin="5" Text="{Binding no}" /> 
           <StackPanel Orientation="Vertical" Grid.Row="0" Grid.Column="1" > 
            <TextBlock Text="{Binding title}" Style="{StaticResource textbold}" Margin="5,0" /> 
            <TextBlock Text="{Binding csoId}" Style="{StaticResource btbx}" Margin="5,0,5,5" HorizontalAlignment="Left" /> 

           </StackPanel> 

           <Image HorizontalAlignment="Right" Grid.Row="0" Grid.Column="2" Source="{Binding imageurl}" Margin="5" Height="25" /> 

           <Image HorizontalAlignment="Left" Grid.Row="1" Grid.Column="0" Source="/Assets/client_icon.png" Margin="5,5,0,5" Width="23"/> 
           <TextBlock Grid.Row="1" Grid.Column="1" Text="{Binding clientname}" Style="{StaticResource textsimple}" /> 

           <Image HorizontalAlignment="Left" Grid.Row="2" Grid.Column="0" Source="/Assets/contact_icon.png" Margin="5,5,0,5" Width="17"/> 
           <TextBlock Grid.Row="2" Grid.Column="1" Text="{Binding customercontact}" Style="{StaticResource textsimple}" /> 

           <Image HorizontalAlignment="Left" Grid.Row="3" Grid.Column="0" Source="/Assets/address_icon.png" Margin="5,5,0,5" Width="20"/> 
           <TextBlock Grid.Row="3" Grid.Column="1" Text="{Binding address}" Style="{StaticResource textsimple}" /> 

           <StackPanel Grid.Row="4" Grid.ColumnSpan="2" Grid.Column="0" Style="{StaticResource mainstp}"> 
            <TextBlock Text="{Binding mydate}" Style="{StaticResource btbx}" /> 
            <TextBlock Text="{Binding mytime}" Style="{StaticResource btbx}" /> 
           </StackPanel> 

           <StackPanel Grid.Row="4" Grid.ColumnSpan="2" Grid.Column="2" Style="{StaticResource mainstp}"> 
            <TextBlock Text="status" Style="{StaticResource btbx}" /> 
            <TextBlock Text="{Binding mystatus}" Style="{StaticResource btbx}" Foreground="Blue"/> 
           </StackPanel> 
           <!--<Button Grid.Row="4" Grid.ColumnSpan="2" VerticalAlignment="Center" HorizontalAlignment="left" Grid.Column="0" Content="{Binding expdate}" Margin="-12,0,-12,-12" Background="#FFD6D6D6" Foreground="Black" Height="80" /> 

           <Button Grid.Row="4" Grid.Column="2" Content="Status" Margin="-10,0,-12,-12" Background="#FFD6D6D6" Foreground="Black" Padding="0,0,5,0" Height="80" />--> 

          </Grid> 

         </Border> 

        </DataTemplate> 
       </phone:LongListSelector.ItemTemplate> 
      </phone:LongListSelector> 

回答

-1

最後我得到的將這個道具在型號

private string _mystatus; 
    public string mystatus 
    { 
     get 
     { 
      return _mystatus; 
     } 
     set 
     { 
      if (value != _mystatus) 
      { 
       _mystatus = value; 
       NotifyPropertyChanged("mystatus"); 
       NotifyPropertyChanged("gridbgc"); 
       NotifyPropertyChanged("buttonfgc"); 
      } 
     } 
    } 
    public string gridbgc 
    { 
     get 
     { 
      switch (mystatus) 
      { 
       case "Checked In": 
        return "#C8D7FF"; 
       case "Pending": 
        return "White"; 
       default: 
        return "White"; 
      } 
     } 
    }  
    public string buttonfgc 
    { 
     get 
     { 
      switch (mystatus) 
      { 
       case "Completed": 
        return "#6FCE2A"; 
       case "Pending": 
        return "C03F40"; 
       default: 
        return "#6691EB"; 
      } 
     } 
    } 
0解決方案

你可以得到這個 「綁定Dynamicall前景色

buttonfgc

<TextBlock Text="{Binding mystatus}" Style="{StaticResource btbx}" Foreground="{Binding buttonfgc}"/> 
+0

你不應該調用NotifyPropertyChanged(」 gridbgc 「) NotifyPropertyChanged(」 buttonfgc「) ,你是不是更新它,這不是根據MVVM strusture – techloverr

+0

@techloverr然後根據MVVM做什麼方式 –

相關問題