-
Notifications
You must be signed in to change notification settings - Fork 11
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
Showing
19 changed files
with
546 additions
and
135 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
namespace Wif.Demo.Common.Interfaces | ||
{ | ||
/// <summary> | ||
/// Use this Interface when you want to mark a control as recieving View | ||
/// Activation when it doesn't have a backing ViewModel. | ||
/// </summary> | ||
public interface IActivatable | ||
{ | ||
} | ||
} |
10 changes: 10 additions & 0 deletions
10
Source/Demos/Wif.Demo.Common/Interfaces/IActivatableView.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,10 @@ | ||
namespace Wif.Demo.Common.Interfaces | ||
{ | ||
/// <summary> | ||
/// Use this Interface when you want to mark a control as receiving View | ||
/// Activation when it doesn't have a backing ViewModel. | ||
/// </summary> | ||
public interface IActivatableView | ||
{ | ||
} | ||
} |
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,30 @@ | ||
namespace Wif.Demo.Common.Interfaces | ||
{ | ||
/// <summary> | ||
/// This base class is mostly used by the Framework. Implement <see cref="IViewFor{T}"/> | ||
/// instead. | ||
/// </summary> | ||
public interface IViewFor : IActivatable | ||
{ | ||
/// <summary> | ||
/// Gets or sets the View Model associated with the View. | ||
/// </summary> | ||
object ViewModel { get; set; } | ||
} | ||
|
||
#pragma warning disable SA1402 // File may only contain a single type | ||
/// <summary> | ||
/// Implement this interface on your Views to support Routing and Binding. | ||
/// </summary> | ||
/// <typeparam name="T">The type of ViewModel.</typeparam> | ||
public interface IViewFor<T> : IViewFor | ||
#pragma warning restore SA1402 // File may only contain a single type | ||
where T : class | ||
{ | ||
/// <summary> | ||
/// Gets or sets the ViewModel corresponding to this specific View. This should be | ||
/// a DependencyProperty if you're using XAML. | ||
/// </summary> | ||
new T ViewModel { get; set; } | ||
} | ||
} |
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,42 @@ | ||
using System.Windows; | ||
using System.Windows.Controls; | ||
using Wif.Demo.Common.Interfaces; | ||
|
||
namespace Wif.Demo.Common | ||
{ | ||
public class UserControlBase<TViewModel> : UserControl, IViewFor<TViewModel> where TViewModel : class | ||
{ | ||
/// <summary> | ||
/// The view model dependency property. | ||
/// </summary> | ||
public static readonly DependencyProperty ViewModelProperty = | ||
DependencyProperty.Register(nameof(ViewModel), typeof(TViewModel), typeof(UserControlBase<TViewModel>), new PropertyMetadata(null)); | ||
|
||
/// <summary> | ||
/// Gets the binding root view model. | ||
/// </summary> | ||
public TViewModel BindingRoot => ViewModel; | ||
|
||
#region IViewFor<TViewModel> Members | ||
|
||
/// <summary> | ||
/// | ||
/// </summary> | ||
public TViewModel ViewModel | ||
{ | ||
get => (TViewModel)GetValue(ViewModelProperty); | ||
set => SetValue(ViewModelProperty, value); | ||
} | ||
|
||
/// <summary> | ||
/// | ||
/// </summary> | ||
object IViewFor.ViewModel | ||
{ | ||
get => ViewModel; | ||
set => ViewModel = (TViewModel)value; | ||
} | ||
|
||
#endregion | ||
} | ||
} |
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 |
---|---|---|
@@ -1,9 +1,7 @@ | ||
<Application x:Class="Wif.Demo.App" | ||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" | ||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" | ||
xmlns:local="clr-namespace:Wif.Demo" | ||
StartupUri="MainWindow.xaml"> | ||
<Application.Resources> | ||
|
||
</Application.Resources> | ||
Exit="App_OnExit" | ||
Startup="App_OnStartup"> | ||
<Application.Resources /> | ||
</Application> |
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
70 changes: 70 additions & 0 deletions
70
Source/Demos/Wif.Demo/Examples/BindingDemo/BindingDemoView.xaml
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,70 @@ | ||
<common:UserControlBase x:TypeArguments="bindingDemo:BindingDemoViewModel" | ||
x:Class="Wif.Demo.Examples.BindingDemo.BindingDemoView" | ||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" | ||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" | ||
xmlns:common="clr-namespace:Wif.Demo.Common;assembly=Wif.Demo.Common" | ||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008" | ||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" | ||
xmlns:bindingDemo="clr-namespace:Wif.Demo.Examples.BindingDemo" | ||
d:DesignHeight="450" | ||
d:DesignWidth="800" | ||
mc:Ignorable="d" > | ||
<UserControl.Resources> | ||
<DataTemplate x:Key="Brand" | ||
DataType="common:MobilePhone"> | ||
<TextBox x:Name="txbBrand" | ||
Text="{Binding Brand}" /> | ||
</DataTemplate> | ||
<DataTemplate x:Key="NumberOfCPUCore" | ||
DataType="common:MobilePhone"> | ||
<TextBox x:Name="txbNumberOfCPUCore" | ||
Text="{Binding NumberOfCPUCore}" /> | ||
</DataTemplate> | ||
<DataTemplate x:Key="RAM" | ||
DataType="common:MobilePhone"> | ||
<TextBox x:Name="txbRAM" | ||
Text="{Binding RAM}" /> | ||
</DataTemplate> | ||
<DataTemplate x:Key="ROM" | ||
DataType="common:MobilePhone"> | ||
<TextBox Name="txbROM" | ||
Text="{Binding ROM}" /> | ||
</DataTemplate> | ||
<DataTemplate x:Key="ScreenResolution" | ||
DataType="common:MobilePhone"> | ||
<TextBox x:Name="txbScreenResolution" | ||
Text="{Binding ScreenResolution}" /> | ||
</DataTemplate> | ||
<DataTemplate x:Key="ScreenSize" | ||
DataType="common:MobilePhone"> | ||
<TextBox x:Name="txbScreenSize" | ||
Text="{Binding ScreenSize, Mode=TwoWay}" /> | ||
</DataTemplate> | ||
|
||
<Style TargetType="TextBox"> | ||
<Setter Property="Padding" | ||
Value="9 5" /> | ||
</Style> | ||
</UserControl.Resources> | ||
<Grid> | ||
<ListView x:Name="ListViewMobiePhone" | ||
ItemsSource="{Binding MobilePhoneCollection}"> | ||
<ListView.View> | ||
<GridView> | ||
<GridViewColumn CellTemplate="{StaticResource Brand}" | ||
Header="品牌" /> | ||
<GridViewColumn CellTemplate="{StaticResource NumberOfCPUCore}" | ||
Header="CPU核数" /> | ||
<GridViewColumn CellTemplate="{StaticResource RAM}" | ||
Header="运行内存" /> | ||
<GridViewColumn CellTemplate="{StaticResource ROM}" | ||
Header="机身内存" /> | ||
<GridViewColumn CellTemplate="{StaticResource ScreenResolution}" | ||
Header="屏幕分辨率" /> | ||
<GridViewColumn CellTemplate="{StaticResource ScreenSize}" | ||
Header="屏幕尺寸 " /> | ||
</GridView> | ||
</ListView.View> | ||
</ListView> | ||
</Grid> | ||
</common:UserControlBase> |
28 changes: 28 additions & 0 deletions
28
Source/Demos/Wif.Demo/Examples/BindingDemo/BindingDemoView.xaml.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,28 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
using System.Windows; | ||
using System.Windows.Controls; | ||
using System.Windows.Data; | ||
using System.Windows.Documents; | ||
using System.Windows.Input; | ||
using System.Windows.Media; | ||
using System.Windows.Media.Imaging; | ||
using System.Windows.Navigation; | ||
using System.Windows.Shapes; | ||
|
||
namespace Wif.Demo.Examples.BindingDemo | ||
{ | ||
/// <summary> | ||
/// BindingDemoView.xaml 的交互逻辑 | ||
/// </summary> | ||
public partial class BindingDemoView | ||
{ | ||
public BindingDemoView() | ||
{ | ||
InitializeComponent(); | ||
} | ||
} | ||
} |
Oops, something went wrong.