كيفية ربط في WPF كائن كله إلى عنصر تحكم المستخدم؟

StackOverflow https://stackoverflow.com/questions/479737

  •  20-08-2019
  •  | 
  •  

سؤال

ويستخدم الناس في كثير من الأحيان شيء من هذا القبيل:

<ListBox ItemsSource="{Binding ElementName=thisControl, Path=ListIndexes}">
<ListBox.ItemTemplate>
<DataTemplate>
<StackPanel>
<Label Content="{Binding Path=IndexName}"/>
<Label Content="{Binding Path=IndexValue}"/>
</StackPanel>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>

ولكن أود أن استخدام بدلا من التسميات، والسيطرة، مثل هذا:

<ListBox ItemsSource="{Binding ElementName=thisControl, Path=ListIndexes}">
<ListBox.ItemTemplate>
<DataTemplate>
<local:Index Item="**{Binding}**"/>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>

وبلدي شك هو ما يتم تنفيذه في هذا الربط لإدراج هذا البند كله من المجموعة.

هل كانت مفيدة؟

المحلول

وبناء الجملة لذلك هو:

<local:Index Item="{Binding}"/>

وهذا سوف اقول البيانات وظائف ملزمة لربط datacontext كامل لكل مربع القائمة البند إلى الخاصية عنصر تحكم في مؤشر بك

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top