Note that there are some explanatory texts on larger screens.

plurals
  1. POWPF Custom Panel From ItemsControl
    text
    copied!<p>I want to create a custom panel where the items are rendered as buttons with close button (x) inside. What i did so far is create a custom control that derives from ItemsControl and set the templates for itemspanel and itemtemplate like this:</p> <p>XAML:</p> <pre><code>&lt;ItemsControl x:Class="SandBox1.CustomControls.WorkspacePanel" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"&gt; &lt;ItemsControl.ItemsPanel&gt; &lt;ItemsPanelTemplate&gt; &lt;StackPanel IsItemsHost="True" Orientation="Horizontal" HorizontalAlignment="Left"/&gt; &lt;/ItemsPanelTemplate&gt; &lt;/ItemsControl.ItemsPanel&gt; &lt;ItemsControl.ItemTemplate&gt; &lt;DataTemplate&gt; &lt;Button Content="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=Name}"/&gt; &lt;/DataTemplate&gt; &lt;/ItemsControl.ItemTemplate&gt; &lt;/ItemsControl&gt; </code></pre> <p>Codebehind:</p> <pre><code>public partial class WorkspacePanel : ItemsControl { public WorkspacePanel() { InitializeComponent(); } } </code></pre> <p>However when i set the ItemsSource i get nothing. Any help?</p> <h1>EDIT</h1> <p>Using the custom control:</p> <pre><code>&lt;cc:WorkspacePanel ItemsSource="{Binding Path=Workspaces}"/&gt; </code></pre> <p>Workspaces is of type <code>ObservableCollection&lt;WorkspaceModel&gt;</code> and WorkspaceModel is:</p> <pre><code>public class WorkspaceModel { public WorkspaceModel(string name, bool isActive) { this.Name = name; this.IsActive = isActive; } public bool IsActive { get; set; } public string Name { get; set; } } </code></pre>
 

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