我正在通过一些在线学习Caliburn.Micro的教程第一次.有些教程使用的是旧的1.3.0版本,我使用的是较新的2.0.0.6版本,这是最新的Nuget软件包,可能是这种差异的根源:
尝试发布以下消息时:
public void Red()
{
_events.Publish(new ColorEvent(new SolidColorBrush(Colors.Red)));
}
Run Code Online (Sandbox Code Playgroud)
编译器抛出一个错误,指出未找到重载.可用的Publish唯一重载具有以下签名:void Publish(object message,Action marshal)
我通过使用下面显示的后台工作线程方法让这个工作,但在我的情况下,它似乎有点矫枉过正.单个参数重载是否真的从Caliburn.Micro中删除了?
此外,文档在这里:https://caliburnmicro.codeplex.com/wikipage?title = The% 20Event%20Aggregator 仍然显示使用更基本的单参数示例的示例,您只需传递一条消息.此链接上的文档是否是正确描述2.0.0.6的最新文档?
public void Red()
{
_events.Publish(new ColorEvent(new SolidColorBrush(Colors.Red)),
action => Task.Factory.StartNew(action));
}
Run Code Online (Sandbox Code Playgroud)
最后,奖励积分:
除了在后台线程上发布消息之外,这第二个参数有什么用呢?有人可以提供一些其他可以用于此重载的示例吗?
要将代码标记为关键部分,我们这样做:
Object lockThis = new Object();
lock (lockThis)
{
//Critical Section
}
Run Code Online (Sandbox Code Playgroud)
为什么需要将对象作为锁语法的一部分?换句话说,为什么不能这样工作:
lock
{
//Critical Section
}
Run Code Online (Sandbox Code Playgroud) 我正在使用 CollectionView 并且当用户选择一个项目时,我根本不希望 SelectedItem 显示背景颜色。我试图通过按照 Xamarin 文档中的说明使用 VisualStateManager 将 BackgroundColor 属性设置为透明来实现这种效果。但是,项目的背景不是不可见,而是在选择时变灰。该代码有效。如果我将它设置为红色,我会看到红色。但我无法让背景完全消失。
这发生在 iOS 中。
谁能告诉我如何做到这一点?
这是我的代码:
<Style TargetType="ContentView">
<Setter Property="VisualStateManager.VisualStateGroups">
<VisualStateGroupList>
<VisualStateGroup x:Name="CommonStates">
<VisualState x:Name="Normal" />
<VisualState x:Name="Selected">
<VisualState.Setters>
<Setter Property="BackgroundColor"
Value="Transparent" />
</VisualState.Setters>
</VisualState>
</VisualStateGroup>
</VisualStateGroupList>
</Setter>
</Style>
<CollectionView Grid.Row="0" ItemsSource="{Binding Lessons}" BackgroundColor="Transparent"
SelectedItem="{Binding SelectedLesson, Mode=TwoWay}" HorizontalOptions="FillAndExpand"
SelectionMode="Single"
cal:Message.Attach="[Event SelectionChanged] = [Action ActivateLesson]">
<CollectionView.ItemTemplate >
<DataTemplate x:DataType="engineVm:LessonViewModel">
<ContentView BackgroundColor="Transparent" cal:View.Model="{Binding}" HorizontalOptions="FillAndExpand" VerticalOptions="FillAndExpand" Margin="0, 0, 0, 20" />
</DataTemplate>
</CollectionView.ItemTemplate>
</CollectionView>
Run Code Online (Sandbox Code Playgroud) 在 Prism MVVM 框架中执行计算属性的最佳方法是什么?我在虚拟机上有一个Xamarin.Forms
具有以下属性的应用程序:
private string _title;
public string Title
{
get { return _title; }
set
{
SetProperty(ref _title, value);
OnPropertyChanged(() => Message);
}
}
private string _name = "John";
public string Name
{
get { return _name; }
set
{
SetProperty(ref _name, value);
OnPropertyChanged(() => Message);
}
}
public string Message
{
get { return String.Format("{0},{1}", Name, Title); }
}
Run Code Online (Sandbox Code Playgroud)
该代码工作得很好。然而,Prism 库警告我OnPropertyChanged
要使用的语句RaisePropertyChanged
,这将避免使用魔术字符串,并且使用表达式的 OnPropertyChanged 效率较低。
是否有其他方法可以在名称或标题更改时通知视图重新读取“消息”?
这让我想到也许 Prism 有一种方法可以进行设置,以便“名称”和“标题”不必知道消息即可更新消息。如果可能的话,这将是更可取的。执行计算属性的“Prism”方式是什么?我在他们的文档中找不到任何示例Xamarin.Forms
。