Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: WPF
Hi! Why does not working bool dependency property of checkbox in UserControl. I want to use it with converter to hide the button control.
 
 <UserControl
    x:Class="MyLib.Legend"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
             mc:Ignorable="d" Height="28" Width="80">
    <Grid  Margin="0,0,0,253">
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="50"></ColumnDefinition>
            <ColumnDefinition Width="30"></ColumnDefinition>            
        </Grid.ColumnDefinitions>
        <Label Margin="0,0,0,-25" Content="График 1" />
        <CheckBox  IsChecked="{Binding ElementName=leg2, Path=IsChecked}" Grid.Column="1" HorizontalAlignment="Left" Height="15" Margin="7,7,0,-22" VerticalAlignment="Top" Width="18"/>
    </Grid>
</UserControl>
 
Legend.xaml.cs
 

 public partial class Legend :UserControl
 
    {
      
        public static readonly DependencyProperty IsCheckedProperty = DependencyProperty.Register("IsChecked", typeof(bool), typeof(Legend), null);
 
        public bool IsChecked
        {
            get { return (bool)GetValue(IsCheckedProperty); }
            set { SetValue(IsCheckedProperty, value); }
        }
 
        public event RoutedEventHandler IsChecked
        {
            add
            {
                base.AddHandler(Legend.MyClickEvent, value);
            }
           remove
            {
                base.RemoveHandler(Legend.MyClickEvent, value);
            }
        }        
 
       
 
        public Legend()
        {
            InitializeComponent();
        }       
    }
 
MainWindow.xaml
 
<Window
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"         
        xmlns:oxy="http://oxyplot.codeplex.com" 
        xmlns:Custom="http://infragistics.com/DataPresenter"        
        xmlns:local="clr-namespace:WpfExamples"      
        xmlns:MyLib="clr-namespace:MyLib;assembly=MyLib" 
        xmlns:MyLibrary="clr-namespace:MyLibrary;assembly=MyLibrary" 
        x:Class="WpfExamples.MainWindow"      
        Title="OxyPlot WPF/XAML examples" Height="628.633" Width="1024.91">
 
    <Grid Margin="0,0,25,48" >
        <Grid.Resources> 
            <local:Title_View2 x:Key="Legend2_View"/>
        </Grid.Resources>
      
        <MyLib:Legend  Name="leg2" HorizontalAlignment="Left" Margin="573,267,0,0" VerticalAlignment="Top"/>
        <Button
            Visibility="{Binding IsChecked, Converter={StaticResource Legend2_View}, ElementName=leg2}" 
            Content="Button" 
            HorizontalAlignment="Left" Margin="591,317,0,0" VerticalAlignment="Top" Width="75"/>
 
    </Grid>
</Window>
 

MainWindow.cs
 
...
 
  public class Title_View2 : IValueConverter
    {
        public object Convert(object value, Type targetTipe, object parameter, CultureInfo culture)
        {
            if (value is bool)
                return ((bool)value) ? Visibility.Visible : Visibility.Collapsed;
 
            return Visibility.Collapsed;
        }
        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            throw new NotImplementedException();
        }
    }
Posted 19-Feb-13 7:00am

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

Hi. i think because of your Dependency Property Name.
IsChecked has defined in Default and compiler encounter with ambiguity. you try try this:
Change your Dependency Property Name from IsChecked to anything. i hope this solve your problem.
goodluck
  Permalink  
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 OriginalGriff 7,205
1 DamithSL 5,114
2 Maciej Los 4,866
3 Sergey Alexandrovich Kryukov 4,747
4 Kornfeld Eliyahu Peter 4,474


Advertise | Privacy | Mobile
Web04 | 2.8.141223.1 | Last Updated 19 Feb 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100