多级可空绑定.1

This commit is contained in:
飞色 开
2023-11-28 12:45:15 +08:00
parent 6d5acbdfac
commit 1ef5f21845
4 changed files with 112 additions and 14 deletions

View File

@@ -110,6 +110,7 @@
<PropertyGroup>
<DefineConstants Condition="'$(TargetFramework)'=='net40'">Net4</DefineConstants>
<AutoGenerateBindingRedirects>false</AutoGenerateBindingRedirects>
<Nullable>disable</Nullable>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(TargetFramework)|$(Platform)'=='Debug|netcoreapp3.0|AnyCPU'">
<Optimize>false</Optimize>

View File

@@ -23,7 +23,37 @@ namespace ConsoleApp1
{
test = this;
}
[PropertyMetadata("我是默认的")]
[PropertyMetadata(null)]
public string Name
{
get
{
return (string)GetValue();
}
set
{
SetValue(value);
}
}
}
public class dataa : CpfObject
{
public data test
{
get
{
return (data)GetValue();
}
set
{
SetValue(value);
}
}
public dataa()
{
// test = new data();
}
[PropertyMetadata(null)]
public string Name
{
get
@@ -38,10 +68,10 @@ namespace ConsoleApp1
}
class MainModel : CpfObject
{
public data Test1 {
public dataa Test1 {
get
{
return (data)GetValue();
return (dataa)GetValue();
}
set
{
@@ -68,7 +98,7 @@ namespace ConsoleApp1
public MainModel()
{
Test1 = new data();
Test1 = new dataa();
Items = new Collection<(string, string)>();
TestItems = new Collection<(string, int)>();

View File

@@ -2454,10 +2454,32 @@ new TabItemTemplate{
},
new Button
{
Content="按钮",
Content="创建对象",
[nameof(Button.Click)]=new CommandDescribe((s,e)=>
{
(DataContext as MainModel).Test1.test.test.test.test.Name = "666666";
data a = new data();
a.test.test.test.Name = "666666";
(DataContext as MainModel).Test1.test = a;
})
},
new Button
{
Content="删除对象",
[nameof(Button.Click)]=new CommandDescribe((s,e)=>
{
data a = new data();
a.test.test.Name = "666666";
(DataContext as MainModel).Test1.test.test = null;
})
},
new Button
{
Content="添加对象",
[nameof(Button.Click)]=new CommandDescribe((s,e)=>
{
data a = new data();
a.test.test.Name = "666666";
(DataContext as MainModel).Test1.test.test = a;
})
},
}