-
-
Save pensacola1989/4134372 to your computer and use it in GitHub Desktop.
MVVMSideKick 用Rx来配置属性之间的关系
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
namespace TableGameSidekick_Metro.Games.DefaultTradeGame.Models | |
{ | |
[DataContract] | |
public class ResourceConfig : BindableBase<ResourceConfig> | |
{ | |
// If you have install the code sniplets, use "propvm + [tab] +[tab]" create a property。 | |
// 如果您已经安装了 MVVMSidekick 代码片段,请用 propvm +tab +tab 输入属性 | |
public ResourceConfig(int players) | |
{ | |
ValidateModel = | |
_ => | |
{ | |
if (CheckError(() => TotalAmount < 0, "ERROR_TotalAmount_LESS_THAN_ZERO")) return; | |
if (CheckError(() => EachPlayerAmount < 0, "ERROR_EachPlayerAmount_LESS_THAN_ZERO")) return; | |
if (HasLimitition) | |
{ | |
if (CheckError(() => EachPlayerAmount * Players > TotalAmount, "ERROR_EACH_PLAYER_AMOUNT_OVERFLOW")) return; | |
} | |
}; | |
this.GetValueContainer(X => X.TotalAmount) | |
.GetValueChangedObservableWithoutArgs() | |
.Merge ( | |
this | |
.GetValueContainer(x => x.HasLimitition) | |
.GetValueChangedObservableWithoutArgs()) | |
.Subscribe( | |
x => | |
{ | |
this.MaxPerPlayer = (this.HasLimitition) ? TotalAmount / players : 1000000; | |
} | |
) | |
.DisposeWith(this); | |
this.GetValueContainer(x => x.MaxPerPlayer) | |
.GetValueChangedObservableWithoutArgs() | |
.Where(_ => this.MaxPerPlayer > this.EachPlayerAmount) | |
.Subscribe(_ => this.EachPlayerAmount = MaxPerPlayer) | |
.DisposeWith(this); | |
} | |
.... | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment