ToggleButton with one way binding
Hello,
I have a ToggleButton in a view, its IsChecked property is bound to the computed property in OneWay mode. I call the PropertyChanged event if one of the elements is changed. It works fine if I don't click toggle button. But if I click on it, property will not reading anymore.
I have created a small view to show you this issue:
I have a ToggleButton in a view, its IsChecked property is bound to the computed property in OneWay mode. I call the PropertyChanged event if one of the elements is changed. It works fine if I don't click toggle button. But if I click on it, property will not reading anymore.
I have created a small view to show you this issue:
Code: Select all
#if UNITY_5_3_OR_NEWER
#define NOESIS
using Noesis;
#else
using System.Windows.Controls;
#endif
using System;
using System.ComponentModel;
using System.Runtime.CompilerServices;
using System.Windows.Input;
using EventHandler = System.EventHandler;
namespace Testing
{
public partial class Main : UserControl, INotifyPropertyChanged
{
private int _checked = 1;
private string _lastPressedButton;
public bool IsChecked1 => _checked == 1;
public bool IsChecked2 => _checked == 2;
public bool IsChecked3 => _checked == 3;
public ICommand CheckCommand1 { get; }
public ICommand CheckCommand2 { get; }
public ICommand CheckCommand3 { get; }
public ICommand ChangeCommand { get; }
public string LastPressedButton
{
get => _lastPressedButton;
set
{
if (value == _lastPressedButton) return;
_lastPressedButton = value;
OnPropertyChanged();
}
}
public Main()
{
CheckCommand1 = new ActionCommand(() =>
{
LastPressedButton = "1";
_checked = 1;
RaiseChecked();
});
CheckCommand2 = new ActionCommand(() =>
{
LastPressedButton = "2";
_checked = 2;
RaiseChecked();
});
CheckCommand3 = new ActionCommand(() =>
{
LastPressedButton = "3";
_checked = 3;
RaiseChecked();
});
ChangeCommand = new ActionCommand(() =>
{
_checked++;
if (_checked > 3)
_checked = 1;
RaiseChecked();
});
InitializeComponent();
}
private void RaiseChecked()
{
OnPropertyChanged(nameof(IsChecked1));
OnPropertyChanged(nameof(IsChecked2));
OnPropertyChanged(nameof(IsChecked3));
}
#if NOESIS
private void InitializeComponent()
{
NoesisUnity.LoadComponent(this);
}
#endif
public event PropertyChangedEventHandler PropertyChanged;
protected virtual void OnPropertyChanged([CallerMemberName] string propertyName = null)
{
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
}
public class ActionCommand : ICommand
{
private readonly Action _action;
public ActionCommand(Action action)
{
_action = action;
}
public bool CanExecute(object parameter)
{
return true;
}
public void Execute(object parameter)
{
_action();
}
public event EventHandler CanExecuteChanged;
}
}
}
Code: Select all
<UserControl x:Class="Testing.Main"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
x:Name="Root">
<StackPanel Orientation="Horizontal" HorizontalAlignment="Center" VerticalAlignment="Center">
<TextBlock Text="{Binding LastPressedButton, ElementName=Root, Mode=OneWay}" />
<ToggleButton IsChecked="{Binding IsChecked1, ElementName=Root, Mode=OneWay}" Command="{Binding CheckCommand1, ElementName=Root}">
<TextBlock Text="1" />
</ToggleButton>
<ToggleButton IsChecked="{Binding IsChecked2, ElementName=Root, Mode=OneWay}" Command="{Binding CheckCommand2, ElementName=Root}">
<TextBlock Text="2" />
</ToggleButton>
<ToggleButton IsChecked="{Binding IsChecked3, ElementName=Root, Mode=OneWay}" Command="{Binding CheckCommand3, ElementName=Root}">
<TextBlock Text="3" />
</ToggleButton>
<Button Command="{Binding ChangeCommand, ElementName=Root}">
<TextBlock Text="Next" />
</Button>
</StackPanel>
</UserControl>
-
-
sfernandez
Site Admin
- Posts: 3363
- Joined:
Re: ToggleButton with one way binding
Hi, this seems a bug in Noesis because I verified it works in Blend just fine. Could you please report it in our bugtracker?
Re: ToggleButton with one way binding
Ok, I created a task:
https://www.noesisengine.com/bugs/view.php?id=2434
https://www.noesisengine.com/bugs/view.php?id=2434
-
-
sfernandez
Site Admin
- Posts: 3363
- Joined:
Re: ToggleButton with one way binding
Thanks for the report, we'll fix it for the next release.
Who is online
Users browsing this forum: No registered users and 4 guests