tag:blogger.com,1999:blog-6130801149335973761.post4040000293788424613..comments2012-04-22T12:09:14.751-07:00Comments on Andu Goes West: WPF: boolean to visibility converterAnduhttp://www.blogger.com/profile/00343924518564969219noreply@blogger.comBlogger11125tag:blogger.com,1999:blog-6130801149335973761.post-2883963321244701892012-04-22T12:09:14.751-07:002012-04-22T12:09:14.751-07:00Thank you!
I've used it in my project.
This ap...Thank you!<br />I've used it in my project.<br />This approach is really better for a simple situations!Mykola Rykovhttps://www.blogger.com/profile/00356113772228474920noreply@blogger.comtag:blogger.com,1999:blog-6130801149335973761.post-76110304279207406922011-08-29T21:17:33.260-07:002011-08-29T21:17:33.260-07:00I wrote a post that extends this post with more in...I wrote a post that extends this post with more information.<br /><br /><a href="http://www.rhyous.com/2011/02/22/binding-visibility-to-a-bool-value-in-wpf/" rel="nofollow">Binding Visibility to a bool value in WPF</a><br /><br />Hope it helps out readers who need a few more examples and need to do a little more customization.Rhyoushttps://www.blogger.com/profile/12742079863966463589noreply@blogger.comtag:blogger.com,1999:blog-6130801149335973761.post-85716581567249428702011-07-01T01:10:26.097-07:002011-07-01T01:10:26.097-07:00This example uses Visibility and not bool:
[Syste...This example uses Visibility and not bool:<br /><br />[System.Windows.Data.ValueConversion(typeof(Synergy.Objects.BusinessEntity), typeof(System.Windows.Visibility))]<br /> public class BusinessEntityRatingClient : System.Windows.Data.IValueConverter<br /> {<br /> public object Convert(object value, Type targetType,<br /> object parameter, System.Globalization.CultureInfo culture)<br /> {<br /> Synergy.Objects.BusinessEntity be = (Synergy.Objects.BusinessEntity)value;<br /><br /> // Need business clients to get this rating<br /> return (be.BusinessClients != null && be.BusinessClients.Count > 0) ? System.Windows.Visibility.Visible : System.Windows.Visibility.Collapsed;<br /> }<br /><br /> public object ConvertBack(object value, Type targetType,<br /> object parameter, System.Globalization.CultureInfo culture)<br /> {<br /> throw new NotImplementedException("Not needed");<br /> }<br /> }GertDhttps://www.blogger.com/profile/17663631778853219339noreply@blogger.comtag:blogger.com,1999:blog-6130801149335973761.post-53722712445393336702010-08-12T11:25:05.863-07:002010-08-12T11:25:05.863-07:00A lot of times, I need to show or hide a textbox b...A lot of times, I need to show or hide a textbox based the value of a checkbox. In WinForms 2.0. This was easy: <br />myTextBox.Visible = myCheckBox.Checked;<br /><br />With the new Visibility Enum in WPF, this becomes a bit trickier. To accomplish this, you need to implement a converter that will accept a boolean value and return a visibility value.Visibilityhttps://www.blogger.com/profile/16940686074296063903noreply@blogger.comtag:blogger.com,1999:blog-6130801149335973761.post-67876532176865994892010-06-08T09:27:33.684-07:002010-06-08T09:27:33.684-07:00[ValueConversion(typeof(bool), typeof(bool))]
...[ValueConversion(typeof(bool), typeof(bool))]<br /> public class BooleanNotConverter : IValueConverter<br /> {<br /> public object Convert(object value, Type targetType, object parameter, CultureInfo culture)<br /> {<br /> if (!targetType.IsAssignableFrom(typeof(bool)))<br /> throw new ArgumentException("targetType must be bool");<br /> if (!(value is bool))<br /> throw new NotSupportedException("value must be a bool");<br /> return !(bool)value;<br /> }<br /><br /> public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)<br /> {<br /> return Convert(value, targetType, parameter, culture);<br /> }<br /> }Unknownhttps://www.blogger.com/profile/08702484074479062976noreply@blogger.comtag:blogger.com,1999:blog-6130801149335973761.post-3406804931835687972010-05-12T15:02:46.462-07:002010-05-12T15:02:46.462-07:00But does it default to collapse or hidden?But does it default to collapse or hidden?Timhttps://www.blogger.com/profile/18223477475853940809noreply@blogger.comtag:blogger.com,1999:blog-6130801149335973761.post-8234473228416790742010-05-12T15:02:09.010-07:002010-05-12T15:02:09.010-07:00Whoa, that really is a winner.Whoa, that really is a winner.Timhttps://www.blogger.com/profile/18223477475853940809noreply@blogger.comtag:blogger.com,1999:blog-6130801149335973761.post-60505469248109844172009-11-13T09:12:02.409-08:002009-11-13T09:12:02.409-08:00// Converter that negates a boolean value
[ValueCo...// Converter that negates a boolean value<br />[ValueConversion(typeof(bool), typeof(bool))]<br />public class NotConverter : IValueConverter<br />{<br /> public object Convert(object value, Type targetType, object parameter, CultureInfo culture)<br /> {<br /> return ConvertValue(value);<br /> }<br /> public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)<br /> {<br /> return ConvertValue(value);<br /> }<br /> private static object ConvertValue(object value)<br /> {<br /> if (!(value is bool))<br /> {<br /> throw new NotSupportedException("Only bool is supported.");<br /> }<br /> return !(bool)value;<br /> }<br />}Unknownhttps://www.blogger.com/profile/07141024522377398917noreply@blogger.comtag:blogger.com,1999:blog-6130801149335973761.post-65983946773969271892009-10-10T11:04:19.887-07:002009-10-10T11:04:19.887-07:00We should make some noise on these weak parts of W...We should make some noise on these weak parts of WPF framework.<br /><br />I opened <a href="https://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=497111" rel="nofollow">suggestion about WPF Boolean inversion converter</a> to Microsoft Connect bug/suggestion system.<br /><br />If you care about this enhancement please vote on it.Ciantichttps://www.blogger.com/profile/09708844807487564418noreply@blogger.comtag:blogger.com,1999:blog-6130801149335973761.post-91042798935231915102009-08-20T05:25:06.286-07:002009-08-20T05:25:06.286-07:00Ignore, I keep forgetting that Silverlight only se...Ignore, I keep forgetting that Silverlight only seems like it is WPF...Anonymoushttps://www.blogger.com/profile/11826644406932697245noreply@blogger.comtag:blogger.com,1999:blog-6130801149335973761.post-57001396926653673542009-08-20T05:20:53.135-07:002009-08-20T05:20:53.135-07:00I thought Wow, cool, this is great!! Now I can'...I thought Wow, cool, this is great!! Now I can't seem to find it. What reference did you have to add? I used the object browser to see if I could find it, went through several references?Anonymoushttps://www.blogger.com/profile/11826644406932697245noreply@blogger.com