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 6: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
Your Filters
Interested
Ignored
     
0 Shai Vashdi 1,518
1 Manas Bhardwaj 319
2 Tadit Dash 285
3 OriginalGriff 273
4 Peter Leow 205
0 Sergey Alexandrovich Kryukov 9,530
1 OriginalGriff 5,716
2 Peter Leow 4,345
3 Maciej Los 3,540
4 Abhinav S 3,373


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