Default Silverlight Content ContentPresenter

Why is this not working?

In generic.xaml for a custom control:

In the style that applies to a custom control ...

<Setter Property="ChromeContent">
  <Setter.Value>
    <Grid />
  </Setter.Value>
</Setter>

...

Later, in the control template ...

<ContentPresenter Grid.Column="0" 
     x:Name="ChromeContentPresenter" 
     Content="{TemplateBinding ChromeContent}" />

Here's the dependency property for ChromeContent ...

public Object ChromeContent
{
  get { return (Object)GetValue(ChromeContentProperty); }
  set { SetValue(ChromeContentProperty, value); }
}
public static readonly DependencyProperty ChromeContentProperty =
    DependencyProperty.Register("ChromeContent", typeof(Object), 
    typeof(casPopup), null);

As you can see, it accepts any object. I tried changing it to a Grid, but that didn't help.

It throws this error (from javascript): _Failed to assign to the 'System.Windows.Controls.ContentPresenter.Content' property

Oddly enough, the following will work fine if I remove the grid from the setter and just use the text:

<Setter Property="ChromeContent" Value="DEFAULT" />

In addition, this will also work with the OnApplyTemplate method in the management class:

  Grid g = new Grid();
  g.Width = 100;
  g.Height = 25;
  g.Background = new SolidColorBrush(Colors.LightGray);
  ChromeContent = g;

It’s hard for me to understand what prevents the standard contents of the grid defined in generic.xaml from working. Does anyone know about this?

!

+5
1

: -

<Setter Property="ChromeContent">
  <Setter.Value>
    <Grid />
  </Setter.Value>
</Setter>

UIElement . , . , . Grid. , ChromeContent, .

A UIElement . , ? ( Silverlight ) Grid .

, ControlTemplate DataTemplate. , , Xaml.

Edit

, DataTemplate: -

<Setter Property="ChromeContentTemplate">
  <Setter.Value>
    <DataTemplate>
      <Grid />
    </DataTemplate>
  </Setter.Value>
</Setter>

: -

public Object ChromeContentTemplate
{
  get { return (DataTemplate)GetValue(ChromeContentTemplateProperty); }
  set { SetValue(ChromeContentTemplateProperty, value); }
}

public static readonly DependencyProperty ChromeContentTemplateProperty=
    DependencyProperty.Register("ChromeContentTemplate", typeof(DataTemplate), 
    typeof(casPopup), null);

: -

<ContentPresenter Grid.Column="0" 
     x:Name="ChromeContentPresenter" 
     Content="{TemplateBinding ChromeContent}"
     ContentTemplate="{TemplateBinding ChromeContentTemplate" />
+6

All Articles