English 中文(简体)
如何在银星建立类似于世界森林基金的数据触发点?
原标题:How to create a WPF-like data trigger in Silverlight?

How might i create a trigger for a Silverlight datagrid in which the cell background color changes based on the cell value? I worked on a WPF project sometime ago and I recall this was quite simple via DataTriggers in the xaml. However this functionality doesn t appear to be available in Silverlight and i m stuck as to where to start.

感谢大家。

最佳回答

第一,更换银灯的触发器是视觉国家感召器。 全民公决实际上比起触发作用要强大得多,因为它允许你在国家变化时执行故事。

如果你不需要估计你的情况,那么我如何解决这个问题,将采用一种四轮运输机。 在数据模板中建立边界,并将背景rush忙与你想要改变背景的影子财产联系起来。

    public class BrushConverter : IValueConverter
{
    public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
    {
       value.ToString() == "Red" ? new SolidColorBrush(Color.Red) : SolidColorBrush(Color.Blue);
    }

    public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
    {
        throw new NotImplementedExcpetion();
    }
}

之后,您的XAML将研究这样的问题:

<Border Background={Binding InterestingProperty,Converter={StaticResource BrushConverter}} />

如果你指定官员需要估计,那么你会再次想读一下视觉国家。 你们所做的基本工作是创造有依赖性财产的模版用户或用户群,然后当这种财产改变决定控制应当属于哪个州,并援引视觉国家经理。 The syntax is such as

VisualStateManager.GoToVisualState(yourControlInstance,"TheState",boolUseTransitions);
问题回答

这是一种使用真实和虚假的粗压的范例。

 public class BoolToBrushConverter:DependencyObject,IValueConverter
  {
    public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
    {
      if(value is bool && (bool)value)
      {
        return TrueBrush;
      }

  return FalseBrush;
}

public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
  throw new NotImplementedException();
}



public Brush FalseBrush
{
  get { return (Brush)GetValue(FalseBrushProperty); }
  set { SetValue(FalseBrushProperty, value); }
}

// Using a DependencyProperty as the backing store for FalseBrush.  This enables animation, styling, binding, etc...
public static readonly DependencyProperty FalseBrushProperty =
    DependencyProperty.Register("FalseBrush", typeof(Brush), typeof(BoolToBrushConverter), new PropertyMetadata(null));



public Brush TrueBrush
{
  get { return (Brush)GetValue(TrueBrushProperty); }
  set { SetValue(TrueBrushProperty, value); }
}

// Using a DependencyProperty as the backing store for TrueBrush.  This enables animation, styling, binding, etc...

public static readonly DependencyProperty TrueBrushProperty =
    DependencyProperty.Register("TrueBrush", typeof(Brush), typeof(BoolToBrushConverter), new PropertyMetadata(null));}

以及

<UserControl.Resources>
    <converter:BoolToBrushConverter x:Key="enabledToBrushConverter"
               TrueBrush="White" FalseBrush="Gray" />
</UserControl.Resources> 

<TextBlock  Foreground="{Binding Element.IsEnabled,
  Converter={StaticResource enabledToBrushConverter}, ElementName= your_Element}"  />




相关问题
Silverlight Rich text box control

Our team decided that we need our own custom Rich text box control for Silverlight app we are developing. We looked at existing controls mentioned at A good rich text control for Silverlight but ...

Silverlight ImageBrush not rendering (with Bing Map Control)

I m trying to add an image to a Pushpin instance from the Silverlight Bing Map Control, but I can t seem to get it to render (the pushpin renders fine). This is probably a general WPF question rather ...

Silverlight OpenFileDialog DoEvents equivalent

I m processing large files after they are selected by the user. My code looks like the following: if (FileDialog.ShowDialog() == true) { // process really big file } This freezes up the UI so ...

list of controls with templates in silverlight

Does anyone know where to find a list of controls that you can set the template on in Silverlight? I ve wasted several hours now trying to create control templates only to find that the control doesn ...

Silverlight, Updating the UI during processing

I have a simple silverlight multifile upload application, and i want to provide the user with some feedback, right now its only in a test phase and i dont have the webservice. Somehow i cant get the ...

Silverlight 3 - FindName returns null

This looks a bug to me.. Using Silverlight 3 and i have a user control defined in XAML and trying to access the object during runtime returns a null. <Grid> <common:CommonGridEditPanel x:...

silverlight 3 collection binding

Someone please help me understand why this binding does not work... I have a class called SelectionManager with a property called dates which is populated by a WCF service. The property is an ...

热门标签