我想这样做,默认情况下,当我绑定到我的一个依赖项属性时,绑定模式是双向的,并且update-trigger属性已更改.有没有办法做到这一点?
以下是我的一个依赖项属性的示例:
public static readonly DependencyProperty BindableSelectionLengthProperty =
DependencyProperty.Register(
"BindableSelectionLength",
typeof(int),
typeof(ModdedTextBox),
new PropertyMetadata(OnBindableSelectionLengthChanged));
Run Code Online (Sandbox Code Playgroud) 是否有MVVM方式在文本框中选择文本?我使用的MVVM框架是Laurent Bugnion的MVVM Light Toolkit.
我需要为每个控件+数字组合创建热键,并且不希望创建十个命令.有没有办法做到这一点?
我确信这很简单,但我无法弄明白.我在这里和msdn上搜索过,但一直无法找到答案.我需要能够通过richtextbox.Selection.Select(TextPointer1,Textpointer2)设置richtextboxes选择.
我有以下代码(不起作用):
private void Window_PreviewKeyDown(object sender, KeyEventArgs e) {
e.Handled = true;
if ((e.Key == Key.P) && (Keyboard.Modifiers == ModifierKeys.Alt)) {
MessageBox.Show("Thanks!");
}
}
Run Code Online (Sandbox Code Playgroud)
为什么这不起作用?事件正在解雇,但是
(e.Key == Key.P) && (Keyboard.Modifiers == ModifierKeys.Alt))
Run Code Online (Sandbox Code Playgroud)
永远不会评估为真.我的类似事件使用Ctrl而不Alt是以这种方式工作.我的活动也包括Ctrl 和 Alt工作.
我在设置窗口中需要一个矩形来显示主窗口的缩小版本.这是我现在所使用的非工作代码.有可能做我想做的事吗?
<Rectangle.Fill>
<VisualBrush Stretch="Uniform" Visual="{Binding ElementName=local:MainWindow}" />
</Rectangle.Fill>
Run Code Online (Sandbox Code Playgroud) 我正在为我的应用程序构建一个设置对话框,现在所有设置都与主视图模型上的设置相对应,但是当我添加更多视图和视图模型时,有些可能没有.
我需要知道将当前设置加载到设置对话框中的最佳做法是什么,然后如果用户单击"确定",则将设置保存到相应的视图模型.
我不会使用Properties.Settings.Default系统来存储设置,因为我希望我的应用程序尽可能便携,这会将用户范围设置存储在目录中:
C:\Users\ username \Local Settings\Application Data\ ApplicationName
而不是在我的应用程序目录中.
如果它有任何区别我使用Laurent Bugnion的MVVM Light Toolkit.
我使用XDocument.Save(路径)将文件保存为xml文档,保存并加载文档后,所有换行符都从"/ r/n"更改为"/ n /".为什么会发生这种情况,我该如何解决?
我得到一个非常奇怪的例外.我得到了例外:
"'Set connectionId threw an exception.' Line number '26' and line position '34'."
当我看到内部异常时,我得到:
"Unable to cast object of type 'System.Windows.Controls.MenuItem' to type 'System.Windows.Controls.ListBox'."
我已将此异常的原因缩小到MenuItem
包含在此的TreeViewItem样式中TreeView
:
<TreeView x:Name="ProjectElementTreeView" ItemsSource="{Binding ProjectElementCollection}" DisplayMemberPath="Name" Padding="0" SelectedItemChanged="ProjectElementTreeView_SelectedItemChanged" GotKeyboardFocus="ProjectElementTreeView_GotKeyboardFocus">
<TreeView.Resources>
<Style TargetType="{x:Type TreeViewItem}">
<Setter Property="HorizontalAlignment" Value="Left" />
<Setter Property="ContextMenu">
<Setter.Value>
<ContextMenu>
<MenuItem Name="AddProjectElementMenuItem" Header="Add" Click="AddProjectElementMenuItem_Click"/>
</ContextMenu>
</Setter.Value>
</Setter>
</Style>
</TreeView.Resources>
</TreeView>
Run Code Online (Sandbox Code Playgroud)
仅当MenuItem
具有单击事件处理程序时才会发生异常,即使单击事件处理程序不包含任何代码也会抛出该异常.
我正在开发一个CustomControl
继承自TextBox
并可以通过Ctrl
在拖动鼠标时按住来调整大小的方法,但有时当你调整它的大小时,线条会像这样被切断:
如果发生这种情况,我想调整选择的高度,这样线条就不会被切断。这是我到目前为止的代码:
double LineHeight = ??;
double requiredHeightAdjustment = this.Height % LineHeight;
if (requiredHeightAdjustment != 0)
{
this.Height -= requiredHeightAdjustment;
}
Run Code Online (Sandbox Code Playgroud)
- 编辑 -
如果将来有人需要这个,这就是我最终得到的:
double fontHeight = this.FontSize * this.FontFamily.LineSpacing;
double requiredHeightAdjustment = this.Height % fontHeight;
var parent = this.Parent as FrameworkElement;
if (requiredHeightAdjustment != 0)
{
double upwardAdjustedHeight = (fontHeight - requiredHeightAdjustment) + this.Height;
if (requiredHeightAdjustment >= fontHeight / 2 && this.MaxHeight >= upwardAdjustedHeight
&& (parent == null || parent.ActualHeight >= upwardAdjustedHeight)) …
Run Code Online (Sandbox Code Playgroud) wpf ×9
c# ×6
mvvm ×2
mvvm-light ×2
textbox ×2
xaml ×2
command ×1
data-binding ×1
exception ×1
key-bindings ×1
keyboard ×1
linq-to-xml ×1
richtextbox ×1
settings ×1
visualbrush ×1
xml ×1