我在我的viewmodel中验证用户输入并在任何值验证失败的情况下抛出验证消息.
我只需要将焦点设置为验证失败的特定控件.
知道怎么做到这一点?
我在wpf mvvm应用程序中实现了一个自定义的富文本框,并且可以选择格式化输入的文本,如下所示:
<Button Style="{StaticResource formatTextStyle}"
Command="EditingCommands.ToggleBold" ToolTip="Bold">
<TextBlock FontWeight="Bold">B</TextBlock>
</Button>
Run Code Online (Sandbox Code Playgroud)
我正在使用EditingCommands.ToggleBold使文本变为粗体.以同样的方式,我给出了ToggleSuperscript的选项
<Button Style="{StaticResource formatImageStyle}"
Command="EditingCommands.ToggleSuperscript" ToolTip="Superscript">
<TextBlock FontStyle="Italic" FontWeight="Bold">SubScript</TextBlock>
</Button>
Run Code Online (Sandbox Code Playgroud)
但它不起作用......
这里是StaticResource
<Style TargetType="{x:Type Button}" x:Key="formatTextStyle">
<Setter Property="FontFamily" Value="Palatino Linotype"></Setter>
<Setter Property="Width" Value="30"></Setter>
<Setter Property="FontSize" Value ="14"></Setter>
<Setter Property="CommandTarget" Value="{Binding ElementName=mainRTB}"/>
</Style>
Run Code Online (Sandbox Code Playgroud)
和mainRTB是我的RichTextBox名称.
<RichTextBox Name="mainRTB" AcceptsTab="True" Height="160"
asis:RichTextboxAssistant.BoundDocument="{Binding Path=Text,
ElementName=uxRichTextEditor}"
VerticalScrollBarVisibility="Visible" />
Run Code Online (Sandbox Code Playgroud)
我对此毫无头绪.任何机构都可以建议如何启用ToggleSuperscript和ToggleSubscript.
我必须在WPF组合框中启用搜索,该组合框显示了WPF MVVM应用程序中的两列。
下面是我的代码,其中显示了两列,例如:名字-姓氏
<ComboBox Grid.Column="3" Grid.Row="15" Height="Auto" HorizontalAlignment="Stretch"
Name="cmbName" VerticalAlignment="Stretch"
SelectedItem="{Binding Name, Mode=TwoWay}"
ItemsSource="{Binding GetAllName}"
IsTextSearchEnabled="True">
<ComboBox.ItemTemplate>
<DataTemplate>
<TextBlock DataContext="{Binding}">
<TextBlock.Text>
<MultiBinding StringFormat="{}{0} - {1}">
<Binding Path="FirstName" />
<Binding Path="LastName" />
</MultiBinding>
</TextBlock.Text>
</TextBlock>
</DataTemplate>
</ComboBox.ItemTemplate>
</ComboBox>
Run Code Online (Sandbox Code Playgroud)
我认为在这种情况下,IsTextSearchEnabled没有发挥任何作用。
有什么帮助吗?
我正在研究一个WPF MVVM项目,并且要求在列表中添加一些函数调用并在循环中调用它们.
假设有这样的函数声明:
public void GetReports(string[] arguments)
{
// My Code
}
public void GetUsers(string[] arguments)
{
// My Code
}
public void GetEmployess(string[] arguments)
{
// My Code
}
Run Code Online (Sandbox Code Playgroud)
并调用我目前使用的这些功能:
GetReports(new string[] { "All" });
GetUsers(new string[] { "All" });
GetEmployess(new string[] { "All" });
Run Code Online (Sandbox Code Playgroud)
现在我需要从List中调用所有这些函数,或者使用其他方法,以便我可以得到no的计数.动态处理一些时间计算的所有函数.
我不能用这个:
List<string> ListFns = new List<string>();
ListFns.Add("GetReports(new string[] { "All" });");
ListFns.Add("GetReports(new string[] { "All" });");
ListFns.Add("GetReports(new string[] { "All" });");
Run Code Online (Sandbox Code Playgroud)
然后我可以像这样迭代:
for (int i = 0; i <= ListFns.Count() - 1; i++) …Run Code Online (Sandbox Code Playgroud) 如何使用MVVM方法以编程方式更改WPF中Window的大小?
我从XAML设置窗口高度为400,并单击窗体上的按钮尝试将高度增加到500.
在我的按钮的ICommand我正在使用:
Application.Current.MainWindow.Height = 500;
Run Code Online (Sandbox Code Playgroud)
但它没有做任何事情.
我使用下面的代码来显示WPF(MVVM)应用程序中的进度条状态,该应用程序基本上是在一个线程上,但是如果我在调度程序线程上放置它的状态没有在UI上更新.
有线程:
Main()
{
Thread LoadApp = new Thread(MyData);
LoadApp.Start();
}
public void MyData()
{
ProgMessage = "10%";
ProgValue = 10;
var varAction = new List<Func<object>>();
varAction .Add(() => (MainViewMode1)ViewModel1.ViewModel1);
varAction .Add(() => (MainViewMode2)ViewModel2.ViewModel2);
varAction .Add(() => (MainViewMode3)ViewModel3.ViewModel3);
foreach (var action in varAction )
{
var obj = action();
ProgressMessage = // My message from VM
ProgressBarValue += // My message valuefrom VM;
}
Run Code Online (Sandbox Code Playgroud)
}
这工作正常但是从现在开始我使用依赖属性我得到了交叉线程异常(STA)所以我将代码更改为:
Main()
{
Application.Current.Dispatcher.Invoke(DispatcherPriority.Background, new Action(() =>
{
MyData();
}));
}
public void MyData()
{ …Run Code Online (Sandbox Code Playgroud)