Note that there are some explanatory texts on larger screens.

plurals
  1. POUsercontrol as datatemplate with bindings
    primarykey
    data
    text
    <p>I have an ItemsControl with ItemsSource binded to a list of SystemModels. It has to generate an usercontrol for every system in the list. And in those usercontrols it has some textboxes that show the name, is and location of the system.</p> <p>My code creates the usercontrols but doesn't fill the textboxes in the usercontrol.</p> <p>View:</p> <pre><code>&lt;UserControl x:Name="SystemListScreen"&gt; &lt;ScrollViewer Grid.Row="1"&gt; &lt;ItemsControl x:Name="SystemList" ItemsSource="{Binding Path=Systems}"&gt; &lt;ItemsControl.ItemsPanel&gt; &lt;ItemsPanelTemplate&gt; &lt;UniformGrid Columns="4"/&gt; &lt;/ItemsPanelTemplate&gt; &lt;/ItemsControl.ItemsPanel&gt; &lt;ItemsControl.ItemTemplate&gt; &lt;DataTemplate DataType="SystemModel"&gt; &lt;Widgets:MultiLineButton partID="{Binding ID}" company="{Binding ItemsSource.Company}" typeSorter="{Binding ItemsSource.Name, ElementName=SystemList}" typeLocation="{Binding ItemsSource.Location, ElementName=SystemList}" buttonCommand="{Binding DataContext.navigateInspectList, ElementName=SystemListScreen}" buttonCommandParameter="{Binding ItemsSource.ID, ElementName=SystemList}"/&gt; &lt;!--&lt;Button Content="{Binding ID}"/&gt;--&gt; &lt;/DataTemplate&gt; &lt;/ItemsControl.ItemTemplate&gt; &lt;/ItemsControl&gt; &lt;/ScrollViewer&gt; &lt;/UserControl&gt; </code></pre> <p>ViewModel:</p> <pre><code>private List&lt;SystemModel&gt; systems; public SystemListViewModel() { Systems = new List&lt;SystemModel&gt;(); Systems = SystemAPI.Instance.GetSystems(); } public string App { get; set; } public List&lt;SystemModel&gt; Systems { get { return systems; } private set { systems = value; NotifyChanged("systems"); NotifyChanged("NoResultsFound"); } } </code></pre> <p>multilinebutton code:</p> <pre><code> public static readonly DependencyProperty buttonCommandProperty = DependencyProperty.Register("buttonCommand", typeof(ICommand), typeof(MultiLineButton)); public static readonly DependencyProperty buttonCommandParameterProperty = DependencyProperty.Register("buttonCommandParameter", typeof(Object), typeof(MultiLineButton)); public static readonly DependencyProperty partIDProperty = DependencyProperty.Register("partID", typeof(String), typeof(MultiLineButton)); public static readonly DependencyProperty companyProperty = DependencyProperty.Register("company", typeof(String), typeof(MultiLineButton)); public static readonly DependencyProperty typeSorterProperty = DependencyProperty.Register("typeSorter", typeof(String), typeof(MultiLineButton)); public static readonly DependencyProperty typeLocationProperty = DependencyProperty.Register("typeLocation", typeof(String), typeof(MultiLineButton)); public MultiLineButton() { this.DataContext = this; InitializeComponent(); } public String partID { get { return (String)GetValue(partIDProperty); } set { SetValue(partIDProperty, value); } } public String company { get { return (String)GetValue(companyProperty); } set { SetValue(companyProperty, value); } } public String typeSorter { get { return (String)GetValue(typeSorterProperty); } set { SetValue(typeSorterProperty, value); } } public String typeLocation { get { return (String)GetValue(typeLocationProperty); } set { SetValue(typeLocationProperty, value); } } public ICommand buttonCommand { get { return (ICommand)GetValue(buttonCommandProperty); } set { SetValue(buttonCommandProperty, value); } } public Object buttonCommandParameter { get { return (Object)GetValue(buttonCommandParameterProperty); } set { SetValue(buttonCommandParameterProperty, value); } } </code></pre> <p>what not works: partID="{Binding ID}", company="{Binding ItemsSource.Company}", typeSorter="{Binding ItemsSource.Name, ElementName=SystemList}", typeLocation="{Binding ItemsSource.Location, ElementName=SystemList}" and buttonCommandParameter="{Binding ItemsSource.ID, ElementName=SystemList}". </p> <p>But if i use just a button as datatemplate with Content="{Binding ID}" It works Perfect, an d if i use the usercontrol outside the datatemplate it works also. But it will not work inside the datatemplate.</p> <p>The error i get is this: "BindingExpression path error: 'Company' property not found on 'object' ''MultiLineButton' (Name='')'. BindingExpression:Path=Company; DataItem='MultiLineButton' (Name=''); target element is 'MultiLineButton' (Name=''); target property is 'company' (type 'String')"</p> <p>How can i fix those bindings?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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