-
Notifications
You must be signed in to change notification settings - Fork 97
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
7faf5a0
commit 4d43044
Showing
8 changed files
with
129 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
37 changes: 37 additions & 0 deletions
37
src/Samples/Common/ViewModels/FeatureSamples/MarkupControl/CommandAsPropertyPageViewModel.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
using DotVVM.Framework.ViewModel; | ||
using DotVVM.Framework.Hosting; | ||
|
||
namespace DotVVM.Samples.Common.ViewModels.FeatureSamples.MarkupControl | ||
{ | ||
public class CommandAsPropertyPageViewModel : DotvvmViewModelBase | ||
{ | ||
|
||
public List<ItemModel> Items { get; set; } = new() { | ||
new ItemModel() { Name = "One", IsTrue = true }, | ||
new ItemModel() { Name = "Two", IsTrue = false }, | ||
new ItemModel() { Name = "Three", IsTrue = true } | ||
}; | ||
|
||
public ItemModel SelectedItem { get; set; } | ||
|
||
public Task MyFunction(string name, bool isTrue) | ||
{ | ||
SelectedItem = new ItemModel() { Name = name, IsTrue = isTrue }; | ||
return Task.CompletedTask; | ||
} | ||
|
||
|
||
public class ItemModel | ||
{ | ||
public string Name { get; set; } | ||
public bool IsTrue { get; set; } | ||
|
||
} | ||
} | ||
} | ||
|
24 changes: 24 additions & 0 deletions
24
src/Samples/Common/Views/FeatureSamples/MarkupControl/CommandAsProperty.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
using DotVVM.Framework.Binding; | ||
using DotVVM.Framework.Controls; | ||
|
||
namespace DotVVM.Samples.Common.Views.FeatureSamples.MarkupControl | ||
{ | ||
public class CommandAsProperty : DotvvmMarkupControl | ||
{ | ||
|
||
public Func<string, bool, Task> Click | ||
{ | ||
get => (Func<string, bool, Task>)GetValue(ClickProperty)!; | ||
set => SetValue(ClickProperty, value); | ||
} | ||
public static readonly DotvvmProperty ClickProperty | ||
= DotvvmProperty.Register<Func<string, bool, Task>, CommandAsProperty>(c => c.Click, null); | ||
|
||
} | ||
} | ||
|
10 changes: 10 additions & 0 deletions
10
src/Samples/Common/Views/FeatureSamples/MarkupControl/CommandAsProperty.dotcontrol
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
@viewModel System.String, mscorlib | ||
@baseType DotVVM.Samples.Common.Views.FeatureSamples.MarkupControl.CommandAsProperty, DotVVM.Samples.Common | ||
|
||
<%-- When uncommented, it produces an error --%> | ||
<%-- In Release mode, the error that is really hard to debug (maybe it was caused because the control was loaded from embedded resource). --%> | ||
<%--<dot:Button Text="{value: _this}" Click="{command: _control.Click}" />--%> | ||
|
||
|
||
<%--The following with ToString works somehow and I am not sure by what magic--%> | ||
<dot:Button Text="{value: _this}" Click="{command: _control.Click.ToString()}" /> |
19 changes: 19 additions & 0 deletions
19
src/Samples/Common/Views/FeatureSamples/MarkupControl/CommandAsPropertyPage.dothtml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
@viewModel DotVVM.Samples.Common.ViewModels.FeatureSamples.MarkupControl.CommandAsPropertyPageViewModel, DotVVM.Samples.Common | ||
|
||
<!DOCTYPE html> | ||
|
||
<html lang="en" xmlns="http://www.w3.org/1999/xhtml"> | ||
<head> | ||
<meta charset="utf-8" /> | ||
<title></title> | ||
</head> | ||
<body> | ||
|
||
<cc:CommandAsPropertyWrapper Click="{command: (string name, bool isTrue) => _root.MyFunction(name, isTrue)}" /> | ||
|
||
<p DataContext="{value: SelectedItem}">Selected item: {{value: Name}}, {{value: IsTrue}}</p> | ||
|
||
</body> | ||
</html> | ||
|
||
|
24 changes: 24 additions & 0 deletions
24
src/Samples/Common/Views/FeatureSamples/MarkupControl/CommandAsPropertyWrapper.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
using DotVVM.Framework.Binding; | ||
using DotVVM.Framework.Controls; | ||
|
||
namespace DotVVM.Samples.Common.Views.FeatureSamples.MarkupControl | ||
{ | ||
public class CommandAsPropertyWrapper : DotvvmMarkupControl | ||
{ | ||
|
||
public Func<string, bool, Task> Click | ||
{ | ||
get { return (Func<string, bool, Task>)GetValue(ClickProperty); } | ||
set { SetValue(ClickProperty, value); } | ||
} | ||
public static readonly DotvvmProperty ClickProperty | ||
= DotvvmProperty.Register<Func<string, bool, Task>, CommandAsPropertyWrapper>(c => c.Click, null); | ||
|
||
} | ||
} | ||
|
10 changes: 10 additions & 0 deletions
10
src/Samples/Common/Views/FeatureSamples/MarkupControl/CommandAsPropertyWrapper.dotcontrol
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
@viewModel DotVVM.Samples.Common.ViewModels.FeatureSamples.MarkupControl.CommandAsPropertyPageViewModel, DotVVM.Samples.Common | ||
@baseType DotVVM.Samples.Common.Views.FeatureSamples.MarkupControl.CommandAsPropertyWrapper, DotVVM.Samples.Common | ||
|
||
<dot:Repeater DataSource="{value: Items}"> | ||
<%-- | ||
The correct syntax would be Click="{value: _control.Click(_parent.Name, _parent.IsTrue)}" | ||
Btw is value binding the right thing, or shall we use resource binding here? | ||
--%> | ||
<cc:CommandAsProperty Click="{value: _control.Click(_parent.Name, _parent.IsTrue)}" DataContext="{value: Name}" /> | ||
</dot:Repeater> |