c# - How to set children Width for DockPanel to 100% inside ComboxItem? -
<comboboxitem horizontalcontentalignment="stretch" width="auto"> <dockpanel background="red" horizontalalignment="stretch" lastchildfill="true" width="auto"> <label dockpanel.dock="left" name="lbname" ></label> <image dockpanel.dock="right" horizontalalignment="right" name="image" source="/test;component/images/cross.jpg" width="16" height="16" stretch="uniformtofill" /> <image dockpanel.dock="right" horizontalalignment="right" name="image2" source="/test;component/images/cross.jpg" width="16" height="16" stretch="uniformtofill" /> </dockpanel> </comboboxitem>
like can see on image below dockpanel
(marked red) doesn't take 100% width of comboboxitem
.
how stretch dockpanel
size of comboboxitem
in xaml?
it turns out, content of comboboxitem
filled entire space, when event selectionchanged
triggered.
example:
xaml
<combobox width="300" height="30" selectionchanged="combobox_selectionchanged"> <comboboxitem>test</comboboxitem> <comboboxitem name="comboboxitem" horizontalcontentalignment="stretch" width="auto"> <dockpanel background="red" horizontalalignment="stretch" width="auto"> ... </dockpanel> </comboboxitem> </combobox>
code-behind
private void combobox_selectionchanged(object sender, selectionchangedeventargs e) { messagebox.show(comboboxitem.actualwidth.tostring()); }
when start application actualwidth
of comboboxitem zero, when selectionchanged
event triggered value 298.
workaround
for workaround add comboboxitem
in begin, example: select item
, set combobox selectedindex="0"
this:
<combobox width="300" height="30" selectedindex="0"> <comboboxitem>select item</comboboxitem> ...
Comments
Post a Comment