Note that there are some explanatory texts on larger screens.

plurals
  1. POUser control with custom properties
    text
    copied!<p>I'm trying to create a UserControl which is a legend of a graph item, I've defined it so it has a label with the graph name, a check box which define whether we show it or not and a rectangle with the graph color.</p> <p>The xaml is defined like this:</p> <pre><code>&lt;UserControl x:Class="Resources.LegendItem" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" mc:Ignorable="d"&gt; &lt;UserControl.Template&gt; &lt;ControlTemplate&gt; &lt;StackPanel Margin="1,0,0,0" Orientation="Horizontal"&gt; &lt;CheckBox Name="cb" IsChecked="{TemplateBinding IsGraphVisible}" &gt; &lt;StackPanel Margin="1,0,0,0" Orientation="Horizontal"&gt; &lt;Rectangle Name="rec" RadiusX="2" RadiusY="2" Height="10" Width="10" /&gt; &lt;Label Name="lab" Content="{TemplateBinding GraphName}" /&gt; &lt;/StackPanel&gt; &lt;/CheckBox&gt; &lt;/StackPanel&gt; &lt;/ControlTemplate&gt; &lt;/UserControl.Template&gt; &lt;/UserControl&gt; </code></pre> <p>and the cs file is:</p> <pre><code>namespace Resources { public partial class LegendItem : UserControl { public static readonly DependencyProperty IsGraphVisibleProperty = DependencyProperty.Register("IsGraphVisible", typeof(Boolean), typeof(LegendItem)); public static readonly DependencyProperty GraphNameProperty = DependencyProperty.Register("GraphName", typeof(String), typeof(LegendItem)); public bool IsGraphVisible { get { return (bool)GetValue(IsGraphVisibleProperty); } set { SetValue(IsGraphVisibleProperty, value); } } public string GraphName { get { return (string)GetValue(GraphNameProperty); } set { SetValue(GraphNameProperty, value); } } public LegendItem() { InitializeComponent(); } } } </code></pre> <p>But when I compile it, I get an error "Cannot find the static member 'IsGraphVisibleProperty' on the type 'Control'." Any help would be appreciated.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload