Roest
Topic Author
Posts: 35
Joined: 15 Jan 2020, 15:30

CheckBox data binding error

30 Mar 2020, 00:09

I can't seem to work out what is needed to do to get checkbox updates on click.
<CheckBox x:Name="CBSuspend" Content="Suspend" IsChecked="{Binding Suspended, Mode=TwoWay}" Margin="10,5,10,5">
NsProp( "Suspended", &Model::GetSuspended, &Model::SetSuspended );
const char* Model::GetSuspended() const
{
	if ( m_suspended )
		return "True";
	return "False";
}

void Model::SetSuspended( const char* value )
{
	...
}
Now the getter is working fine but when I click the checkbox Noesis responds with an error message and the setter is never called. What am I missing here?
E No converter available to convert binding value 'null' (type 'const Char*')
 
User avatar
sfernandez
Site Admin
Posts: 2983
Joined: 22 Dec 2011, 19:20

Re: CheckBox data binding error

30 Mar 2020, 13:08

CheckBox.IsChecked property is of type Nullable<bool>, you can just use a bool property in the view model. The getter and setter signature in that case is:
bool GetSuspended() const;
void SetSuspended(bool value);
Let me know if you have any problems using bool.
 
Roest
Topic Author
Posts: 35
Joined: 15 Jan 2020, 15:30

Re: CheckBox data binding error

30 Mar 2020, 16:22

thanks that worked
 
Roest
Topic Author
Posts: 35
Joined: 15 Jan 2020, 15:30

Re: CheckBox data binding error

30 Mar 2020, 20:54

Ok one more question. How would that work when I want to make the CheckBox tristate, which I guess is the Nullable for.

So I have something like
Noesis::Nullable<bool> Model::getState() const
{
return nullptr;
}
That compiles for itself but fails on Implement-Reflection with
Severity Code Description Project File Line Suppression State
Error C2664 'Noesis::TypePropertyFunction<ClassT,Type>::TypePropertyFunction(const Noesis::TypePropertyFunction<ClassT,Type> &)': cannot convert argument 2 from 'T (__cdecl IngnomiaGUI::CategoryItem::* )(void) const' to 'const Noesis::Nullable<bool> &(__cdecl IngnomiaGUI::CategoryItem::* )(void) const' \libs\NoesisGUI-NativeSDK-2.2.6\Include\NsCore\TypeClassCreator.inl 122
 
User avatar
sfernandez
Site Admin
Posts: 2983
Joined: 22 Dec 2011, 19:20

Re: CheckBox data binding error

30 Mar 2020, 21:38

If you need the tree states of the IsChecked then you need a Nullable<bool> property with the following signature for the getter/setter:
const Noesis::Nullable<bool>& GetState() const;
void SetState(const Noesis::Nullable<bool>& value);
And a member variable of type Nullable<bool>:
Noesis::Nullable<bool> _state;

Who is online

Users browsing this forum: Ahrefs [Bot], Google [Bot] and 88 guests