How to get rid of annoying HorizontalContentAlignment binding warning?
This worked for me. Put this in your Application.xaml file.
<Application.Resources> <Style TargetType="ComboBoxItem"> <Setter Property="HorizontalContentAlignment" Value="Left" /> <Setter Property="VerticalContentAlignment" Value="Center" /> </Style></Application.Resources>
from...
http://social.msdn.microsoft.com/Forums/en-US/wpf/thread/42cd1554-de7a-473b-b977-ddbd6298b3d0
I don't know if after more than a year your are still interested in this problem but my solution was to explicitly write in the style the value for this. For example:
<Style x:Key="{x:Type ComboBoxItem}" TargetType="{x:Type ComboBoxItem}"> <Setter Property="HorizontalContentAlignment" Value="Stretch"/>
And that simply solved that problem.
I just want to mention I struggled with a similar problem for two days (mine was a "Windows Data Error 4" error, complaining about HorizontalContentAlignment
and VerticalContentAlignment
).
The most common suggested solution (adding the Horizontal/VerticalContentAlignment Style to your element, or even to the App.xaml) does NOT always solve the problem.
Eventually, I discovered something unique to my own situation - I hope it can be of help to someone: If you are using the FilterEventHandler
, don't unsubscribe it before resubscribing!
My old code kept on generating that "Data Error 4" message whenever I changed the Channel Filter (which calls UpdateCorporatesList
):
// This code generates errorsprivate void UpdateCorporatesList(){ this.CorporatesViewSource.Filter -= new FilterEventHandler(ApplyCorporateFilter); if (this.ChannelFilter != null) { this.CorporatesViewSource.Filter += new FilterEventHandler(ApplyCorporateFilter); } else { this.CorporateFilter = null; }}private void ApplyCorporateFilter(object sender, FilterEventArgs e){ SalesCorporate customer = e.Item as SalesCorporate; var currentChannel = this.Channels.FirstOrDefault(x => x.ID == this.ChannelFilter).Description; if ((customer.ID != null) && (customer.Channel != currentChannel)) { e.Accepted = false; }}
...so I changed it to re-subscribe to the FilterEventHandler every time, and rather put the check for a null on Channel Filter in the event-handling method.
// This code works as intendedprivate void UpdateCorporatesList(){ this.CorporatesViewSource.Filter += new FilterEventHandler(ApplyCorporateFilter); if (this.ChannelFilter == null) { this.CorporateFilter = null; }}private void ApplyCorporateFilter(object sender, FilterEventArgs e){ var currentChannel = this.Channels.FirstOrDefault(x => x.ID == this.ChannelFilter); if (currentChannel.ID == null) { return; } SalesCorporate customer = e.Item as SalesCorporate; if ((customer.ID != null) && (customer.Channel != currentChannel.Description)) { e.Accepted = false; }}
Et Voila! No more errors :-)