Ich versuche eine benutzerdefinierte ComboBox
erstellen, die eine DataGrid
als PopUp
hat. Ich überschrieben den Standard Template
, aber wenn ich die ItemsHost
zum DataGrid
(IsItemsHost="True"
) setze ich erhalte The member "IsItemsHost" is not recognized or is not accesible
(wie erwartet)ComboBox mit DataGrid PopUp
<Popup Name="Popup"
Placement="Bottom"
IsOpen="{TemplateBinding IsDropDownOpen}"
AllowsTransparency="True"
Focusable="False"
PopupAnimation="Slide">
<Grid Name="DropDown"
SnapsToDevicePixels="True"
MinWidth="{TemplateBinding ActualWidth}"
MaxHeight="{TemplateBinding MaxDropDownHeight}">
<Border x:Name="DropDownBorder"
Background="White"
BorderThickness="1"
BorderBrush="LightGray"/>
<ScrollViewer Margin="1,2" SnapsToDevicePixels="True">
<DataGrid IsItemsHost="True" KeyboardNavigation.DirectionalNavigation="Contained" />
</ScrollViewer>
</Grid>
</Popup>
Wie kann ich das umsetzen?
Fortschritt:
Nach Microsoft:
Wenn Sie eine Control für eine ComboBox erstellen, Ihre Vorlage könnte eine Itemspresenter innerhalb eines Scroll enthalten. (Der ItemsPresenter zeigt jedes Element in der ComboBox an; der ScrollViewer ermöglicht das Scrollen innerhalb des Steuerelements). Wenn der ItemsPresenter nicht das direkte Kind des ScrollViewers ist, müssen Sie dem ItemsPresenter den Namen ItemsPresenter geben.
So funktioniert das (wenn ich eine komplette Lösung habe ich es als Antwort hinzufügen wird):
<Popup Name="Popup"
Placement="Bottom"
IsOpen="{TemplateBinding IsDropDownOpen}"
AllowsTransparency="True"
Focusable="False"
PopupAnimation="Slide">
<Grid Name="DropDown"
SnapsToDevicePixels="True"
MinWidth="{TemplateBinding ActualWidth}"
MaxHeight="{TemplateBinding MaxDropDownHeight}">
<Border x:Name="DropDownBorder"
Background="White"
BorderThickness="1"
BorderBrush="LightGray"/>
<ScrollViewer Margin="1,2" SnapsToDevicePixels="True">
<StackPanel Orientation="Vertical" >
<DataGrid x:Name="ItemsPresenter" ItemsSource="{TemplateBinding ItemsSource}" KeyboardNavigation.DirectionalNavigation="Contained"></DataGrid>
<Border Height="10" Background="Red" />
</StackPanel>
</ScrollViewer>
</Grid>
</Popup>
, wo und wie wird dieses Popup angezeigt/present würde gezeigt /? – AnjumSKhan
Dies ist der 'Popup'-Teil der überschriebenen' ComboBox' 'Template'. Ich kann das vollständige 'Template' hinzufügen, wenn es hilfreich ist –