View Issue Details
| ID | Project | Category | View Status | Date Submitted | Last Update |
|---|---|---|---|---|---|
| 0002434 | NoesisGUI | Unity | public | 2022-09-27 13:58 | 2024-12-26 19:08 |
| Reporter | jetjalopy | Assigned To | sfernandez | ||
| Priority | normal | Severity | minor | ||
| Status | resolved | Resolution | fixed | ||
| Product Version | 3.1.5 | ||||
| Target Version | 3.2.7 | Fixed in Version | 3.2.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 |
| ||||
| Attached Files | 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;
}
}
} | ||||
| Platform | Windows | ||||
| related to | 0003009 | resolved | sfernandez | One way binding on checkbox to a bool breaks if the checkbox is clicked |
| related to | 0003429 | resolved | sfernandez | RadioButton selection cannot be controlled correctly from code when using OneWay Binding. |
|
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. |
|
|
Fixed in changeset 14847 |
|
| 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 | |
| 2024-01-15 11:41 | sfernandez | Relationship added | related to 0003009 |
| 2024-06-24 12:38 | sfernandez | Relationship added | related to 0003429 |
| 2024-12-26 19:08 | sfernandez | Status | feedback => resolved |
| 2024-12-26 19:08 | sfernandez | Resolution | open => fixed |
| 2024-12-26 19:08 | sfernandez | Fixed in Version | => 3.2.7 |
| 2024-12-26 19:08 | sfernandez | Target Version | 3.1.7 => 3.2.7 |
| 2024-12-26 19:08 | sfernandez | Note Added: 0010226 | |
| 2025-10-10 13:29 | jsantos | Category | Unity3D => Unity |