Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>If you are dealing with booleans and visibility you should consider a <a href="http://msdn.microsoft.com/en-us/library/system.windows.data.ivalueconverter.aspx" rel="nofollow">ValueConverter</a>.</p> <p>Here's an example on how to bind to a boolean (<code>IsTextVisible</code>) in your model and have it map to visibility collapsed or visible.</p> <p><strong>XAML:</strong></p> <pre><code> &lt;TextBox HorizontalAlignment="Center" VerticalAlignment="Center" Canvas.Left="16" Canvas.Top="8" Width="16" x:Name="TxtCantidad" Style="{StaticResource TransformerBox}" Height="23" Visibility="{Binding IsTextVisible, Converter={StaticResource BoolToVisibilityConverter}}"/&gt; </code></pre> <p><strong>ValueConverter code:</strong></p> <pre><code>public class BoolToVisibilityConverter : IValueConverter { object IValueConverter.Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture) { bool isVisible = Convert.ToBoolean(value); return isVisible ? Visibility.Visible : Visibility.Collapsed; } object IValueConverter.ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture) { throw new NotImplementedException(); } } </code></pre> <p>Also you have to import the converter namespace in your XAML </p> <pre><code>xmlns:converter="clr-namespace:Foo.Converter" </code></pre> <p>and assign it a key</p> <pre><code>&lt;converter:BoolToVisibilityConverter x:Key="BoolToVisibilityConverter"/&gt; </code></pre> <p><strong>EDIT:</strong></p> <p>If you're binding directly to the code behind for your purposes you can set the DataContext for the Window in the XAML this way</p> <pre><code> DataContext="{Binding RelativeSource={RelativeSource Self}}" </code></pre> <p>Also make sure you are binding to a property</p> <pre><code>public bool IsTextVisible {get;set;} </code></pre> <p>In the long run you will want to look into the following topics:</p> <ol> <li><a href="http://msdn.microsoft.com/en-us/magazine/cc163299.aspx" rel="nofollow">Data Binding in WPF</a></li> <li><a href="http://msdn.microsoft.com/en-us/magazine/dd419663.aspx" rel="nofollow">MVVM in WPF</a></li> </ol>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload