Reputation: 4777
I have a XAML/WPF custom control that is used to display a list of items. I initially set this controls Width to Auto as I want it to rezize to the width of the widest item added to it.
<custom:MyCustomControl ThemeName="MyDefaultTHeme"
x:Name="PART_MyItems"
Height="Auto"
Width="Auto"/>
However, during runtime the user can change the ControlTemplate (ThemeName) of my custom control which changes how the items look (Icon and text size etc). The control will then change its width according to the width of the items and can sometimes fill up the entire width of the screen. This I do not want.
How can I either, turn off Width="Auto"
after the first use (First load of control) or set the width to the initial width and not change it again>
Upvotes: 2
Views: 751
Reputation: 3880
Just call MyCustomControl.Width = MyCustomControl.ActualWidth
before you change its theme, since you probably have C# code doing the theme switch. That will get rid of the Auto
.
Upvotes: 2