Note that there are some explanatory texts on larger screens.

plurals
  1. POConverting ControlTemplate XAML to C#
    text
    copied!<p>I have been stumped with trying to convert the following code into pure c#. This XAML code is from Cavanaghs blog on how to make rounded corners on anything. The code works but I need to convert it to c# as i need it to be dynamic in some cases. If you could help that would be great.</p> <pre><code>&lt;Setter Property="Template"&gt; &lt;Setter.Value&gt; &lt;ControlTemplate TargetType='{x:Type ListViewItem}'&gt; &lt;Grid&gt; &lt;Border CornerRadius="15" Name="mask" Background="White"/&gt; &lt;StackPanel Background="Beige"&gt; &lt;StackPanel.OpacityMask&gt; &lt;VisualBrush Visual="{Binding ElementName=mask}"/&gt; &lt;/StackPanel.OpacityMask&gt; &lt;GridViewRowPresenter Content="{TemplateBinding Content}" Columns="{TemplateBinding GridView.ColumnCollection}"/&gt; &lt;TextBlock Background="LightBlue" Text="{Binding News}" /&gt; &lt;/StackPanel&gt; &lt;/Grid&gt; &lt;/ControlTemplate&gt; &lt;/Setter.Value&gt; </code></pre> <p></p> <p>So far I have the following but I am getting errors.</p> <pre><code>FrameworkElementFactory border = new FrameworkElementFactory(typeof(Border)); border.SetValue(Border.BackgroundProperty, Brushes.White); border.SetValue(Border.CornerRadiusProperty, new CornerRadius(8, 8, 8, 8)); border.SetValue(Border.NameProperty, "roundedMask"); </code></pre> <p>As far as I can tell I cant make the VisualBrush as a FrameworkElementFactory (crashes), but if i declare it as a regular element VisualBrush i cant pass border in as a Visual since its a FrameworkElementFactory.</p> <p>Simply i am getting lost, any help would be appreciated. Thanks for any help </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