Fix MultiComboBox to works with items added in axaml
This commit is contained in:
@@ -11,6 +11,8 @@
|
|||||||
x:CompileBindings="True"
|
x:CompileBindings="True"
|
||||||
x:DataType="vm:MultiComboBoxDemoViewModel"
|
x:DataType="vm:MultiComboBoxDemoViewModel"
|
||||||
mc:Ignorable="d">
|
mc:Ignorable="d">
|
||||||
|
<StackPanel Orientation="Vertical" Spacing="10">
|
||||||
|
<TextBlock>Binded ItemsSource</TextBlock>
|
||||||
<StackPanel Orientation="Horizontal">
|
<StackPanel Orientation="Horizontal">
|
||||||
<u:MultiComboBox
|
<u:MultiComboBox
|
||||||
Watermark="Please Select"
|
Watermark="Please Select"
|
||||||
@@ -19,6 +21,7 @@
|
|||||||
SelectedItems="{Binding SelectedItems}"
|
SelectedItems="{Binding SelectedItems}"
|
||||||
ItemsSource="{Binding Items}" >
|
ItemsSource="{Binding Items}" >
|
||||||
</u:MultiComboBox>
|
</u:MultiComboBox>
|
||||||
|
|
||||||
<u:MultiComboBox
|
<u:MultiComboBox
|
||||||
Name="combo"
|
Name="combo"
|
||||||
Watermark="Please Select"
|
Watermark="Please Select"
|
||||||
@@ -42,6 +45,18 @@
|
|||||||
</MenuFlyout>
|
</MenuFlyout>
|
||||||
</u:MultiComboBox.ContextFlyout>
|
</u:MultiComboBox.ContextFlyout>
|
||||||
</u:MultiComboBox>
|
</u:MultiComboBox>
|
||||||
|
|
||||||
<ListBox ItemsSource="{Binding SelectedItems}" />
|
<ListBox ItemsSource="{Binding SelectedItems}" />
|
||||||
</StackPanel>
|
</StackPanel>
|
||||||
|
|
||||||
|
<TextBlock>Items inside axaml (u:MultiComboBox's tag content)</TextBlock>
|
||||||
|
<u:MultiComboBox
|
||||||
|
Watermark="Please Select"
|
||||||
|
Width="300"
|
||||||
|
MaxHeight="200">
|
||||||
|
<u:MultiComboBoxItem>option 1</u:MultiComboBoxItem>
|
||||||
|
<u:MultiComboBoxItem>option 2</u:MultiComboBoxItem>
|
||||||
|
<u:MultiComboBoxItem>option 3</u:MultiComboBoxItem>
|
||||||
|
</u:MultiComboBox>
|
||||||
|
</StackPanel>
|
||||||
</UserControl>
|
</UserControl>
|
||||||
|
|||||||
@@ -179,6 +179,14 @@ public class MultiComboBox : SelectingItemsControl, IInnerContentControl, IPopup
|
|||||||
return new MultiComboBoxItem();
|
return new MultiComboBoxItem();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected override void PrepareContainerForItemOverride(Control container, object? item, int index)
|
||||||
|
{
|
||||||
|
if (item is MultiComboBoxItem containerItem)
|
||||||
|
{
|
||||||
|
container.DataContext = containerItem.Content;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
protected override void OnApplyTemplate(TemplateAppliedEventArgs e)
|
protected override void OnApplyTemplate(TemplateAppliedEventArgs e)
|
||||||
{
|
{
|
||||||
base.OnApplyTemplate(e);
|
base.OnApplyTemplate(e);
|
||||||
|
|||||||
Reference in New Issue
Block a user