WPF custom user control blinding not working

  • Thread starter Thread starter Btb4198
  • Start date Start date
B

Btb4198

Guest
My WPF custom user control blinding not working. The color is not being set. so during run time, the color is blank.


here is my WPF code :

<Ellipse Canvas.Left="12.25" Canvas.Top="12.25" Width="75" Height="75" StrokeThickness="0.5" Stroke="Black">
<Ellipse.Fill>
<RadialGradientBrush Center="0.6, 0.35" GradientOrigin="0.6,0.3" RadiusY="0.67" RadiusX="0.67">
<RadialGradientBrush.RelativeTransform>
<TransformGroup>
<ScaleTransform CenterY="0.35" CenterX="0.6" ScaleY="1" ScaleX="1" />
<SkewTransform AngleY="0" AngleX="0" CenterY="0.35" CenterX="0.6" />
<RotateTransform Angle="-4.447" CenterY="0.35" CenterX="0.6" />
<TranslateTransform X="0" Y="0"/>
</TransformGroup>
</RadialGradientBrush.RelativeTransform>
<GradientStop Color="White" Offset="0"/>
<GradientStop Color="{Binding Ellipsecolor, Mode=OneWay, UpdateSourceTrigger=PropertyChanged}"/>
</RadialGradientBrush>
</Ellipse.Fill>
</Ellipse>



Here is my c# code:

public partial class UserControl1 : UserControl, INotifyPropertyChanged
{
public UserControl1()
{
InitializeComponent();
this.DataContext = this;
LEDState(2);


}

GradientStop _ellipseColors= new GradientStop(Colors.Yellow,1);
int _state;


public int State
{
get
{
return _state;
}

set
{
if (value != _state)
{
_state = value;
LEDState(_state);
}
}

}


public GradientStop Ellipsecolor
{
get
{
return _ellipseColors;
}

set
{
if (value != _ellipseColors)
{
_ellipseColors = value;
onPropertyChanged("Ellipsecolor");
}
}
}


public static readonly DependencyProperty StateProperty = DependencyProperty.Register(
"State", typeof(int), typeof(UserControl1), new FrameworkPropertyMetadata(OnStateChanged)
);

private static void OnStateChanged(DependencyObject src, DependencyPropertyChangedEventArgs e)
{
UserControl1 state = src as UserControl1;
state.LEDState((int)e.NewValue);
//state. //tbnMainToggleButton.IsChecked = e.NewValue as bool?;
}


private void OnAsyncOperationCompleted()
{

Application.Current.Dispatcher.BeginInvoke(new Action(() => {
// Update the UI
}));
}


public void LEDState( int state)
{

switch (state)
{
case 1:

Ellipsecolor.Color = Colors.LimeGreen;

break;
case 2:
Ellipsecolor.Color = Colors.Red;
break;
case 3:
Ellipsecolor.Color = Colors.Yellow;
break;

default:
Ellipsecolor.Color = Colors.Yellow;
break;
}


}

public event PropertyChangedEventHandler PropertyChanged;
private void onPropertyChanged(String propertyName)
{
if (PropertyChanged != null)
{
PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
}
}


}





Now I have been trying to troubleshoot this in debug mode and the function LEDState does get called , a value 2 is sent to it.

then OnPropertyChanged("Ellipsecolor") is called

but the Color still is not set.


now if I replace "{Binding Ellipsecolor, Mode=OneWay, UpdateSourceTrigger=PropertyChanged}" with <GradientStop Color="Red" Offset="1"/> is does work . and the color is red.


So something is wrong with the blinding...

also,

private static void OnStateChanged(DependencyObject src, DependencyPropertyChangedEventArgs e)
{
UserControl1 state = src as UserControl1;
state.LEDState((int)e.NewValue);
//state. //tbnMainToggleButton.IsChecked = e.NewValue as bool?;
}


Is called and it have a value of 1 and LEDState is called but Ellipsecolor is not called after.


so there are two problems with this code.

Continue reading...
 

Similar threads

Back
Top