View Issue Details
ID | Project | Category | View Status | Date Submitted | Last Update |
---|---|---|---|---|---|
0002434 | NoesisGUI | Unity3D | public | 2022-09-27 13:58 | 2023-09-04 18:44 |
Reporter | jetjalopy | Assigned To | sfernandez | ||
Priority | normal | Severity | minor | Reproducibility | always |
Status | feedback | Resolution | open | ||
Product Version | 3.1.5 | ||||
Target Version | 3.1.7 | ||||
Summary | 0002434: ToggleButton with one way binding | ||||
Description | 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. Forum discussion: https://www.noesisengine.com/forums/viewtopic.php?t=2731 | ||||
Steps To Reproduce | 1. Create a toggle button in a xaml with a one way binding. 2. Create a computed property. 3. Raise a property changed event. 4. Click on the toggle button. 5. Raise a property changed event. | ||||
Tags | Unity | ||||
Platform | Windows | ||||
Main.xaml (1,074 bytes)
<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> Main.xaml.cs (3,135 bytes)
#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; } } } |
|
I'm hitting this same issue, a fix would be nice. | |
Is this happening to you with NoesisGUI 3.2.1? | |
For me I'm using NoesisGUI 3.2.1 on Windows (not Unity). This issue seemed related although I may be hitting something similar. I tried RadioButton and ToggleButton with OneWay and TwoWay bindings, but whenever I clicked a button, the IsChecked binding stopped working. I ended up styling a ListBox to look like radio buttons. If I'm hitting a different issue I can log a new bug, I'd rather use RadioButtons instead of a ListBox. |
|
Date Modified | Username | Field | Change |
---|---|---|---|
2022-09-27 13:58 | jetjalopy | New Issue | |
2022-09-27 13:58 | jetjalopy | Tag Attached: Unity | |
2022-09-27 13:58 | jetjalopy | File Added: Main.xaml | |
2022-09-27 13:58 | jetjalopy | File Added: Main.xaml.cs | |
2022-09-27 18:18 | sfernandez | Assigned To | => sfernandez |
2022-09-27 18:18 | sfernandez | Status | new => assigned |
2022-09-27 18:18 | sfernandez | Target Version | => 3.1.6 |
2022-11-07 17:13 | sfernandez | Target Version | 3.1.6 => 3.1.7 |
2023-09-01 08:14 | spadapet | Note Added: 0008690 | |
2023-09-04 16:03 | sfernandez | Status | assigned => feedback |
2023-09-04 16:03 | sfernandez | Note Added: 0008695 | |
2023-09-04 18:44 | spadapet | Note Added: 0008696 |