小编Dav*_*ave的帖子

需要带有 TextTrimming 和 MaxLines 的 WPF TextBlock 或 TextBox

我需要一个具有 TextTrimming 和 MaxLines 的 TextBlock 或 TextBox。TextBlock 有一个 TextTrimming 属性,TextBox 有一个 MaxLines 属性,但两者都不支持。这是一个更大的控件的一部分,允许用户输入笔记并将它们显示在列表框中(请参阅: Grief with WPF UserControl with ListBox and TextBox Can't get textwrapping to work如果有兴趣)。基本上,对于已经输入的笔记,我想将笔记限制为 2 行。如果它长于 2 行,我会在它的末尾显示一个椭圆 (...) 以表示注释还有更多内容。如果用户将鼠标悬停在缩写的笔记上,他/她会看到整个笔记作为弹出窗口。* 该控件将放置在主网格上,并且可能具有不同的大小(或调整大小),因此 2 行中的文本数量可能会发生变化. 即在某些情况下可以完全显示的注释在其他情况下可能会被缩写。

尝试将 MaxLines 功能添加到 TextBlock 或将 TextTrimming 添加到 TextBox 会更好吗?我看到一些帖子似乎与我需要做的很接近。这是一个将 TextTrimming 添加到 TextBox 但仅在编辑时并且不清楚 MaxLines 是否仍然有效的方法: TextBox TextTrimming 我没有遇到任何关于将 MaxLines 属性添加到 TextBlock 的问题。请注意,Windows Phone 的 TextBlock 似乎有它。也许我不是唯一需要这个的人:)

我有点惊讶这不是“开箱即用”的。这似乎是一个普遍的问题。顺便说一句,对于 TextBox、TextBlock,甚至 Label 或其他东西,都没有偏好。这些只是列表框项目,不可编辑。

任何想法或指针都非常感谢。

-Dave *如果您在想,“当用户将鼠标悬停在缩写注释上时,他接下来可能会询问如何显示弹出窗口”,您说得非常正确!

这是一种基于此 stackoverflow 帖子处理该问题的方法:可 滚动的 TextBlock 大小正好为 2 …

wpf styles textbox listbox textblock

3
推荐指数
1
解决办法
6079
查看次数

关于从同一个线程调用的WPF Dispatcher.BeginInvoke的问题!为什么?

我对WPF比较陌生.我正在检查一些看起来像这样的代码:

private void button_Click(object sender, RoutedEventArgs e)
{
    //Queue on dispatcher in the background so it doesn't make the UI slow
        Dispatcher.BeginInvoke(new dMyDelegate(PerformOperation), DispatcherPriority.Background);
}
Run Code Online (Sandbox Code Playgroud)

从评论中,我猜测原始代码认为这对于使UI更具响应性是必要的,但是,我的理解是Dispatcher.BeginInvoke只是在UI线程上运行某些东西.由于buttn_Click已经在UI线程上,有什么意义呢?也许我误解了Dispatcher和BeginInvoke.在这种情况下,我假设Dispatcher是此方法所在的类所拥有的调度程序,即MainWindow.xaml.有人可以开导我吗?

谢谢

wpf dispatcher begininvoke

2
推荐指数
1
解决办法
1037
查看次数

在WPF DataGrid中实现编辑和双击(MouseDoubleClick)。

我已经用DataGrid编码了WPF UserControl。我添加了使用“单击编辑”来编辑一列(RecordingName)的功能(请参阅:我的代码和http://wpf.codeplex.com/wikipage?title=Single-Click%20Editing)。我还在处理整个DataGrid的MouseDoubleClick事件。

它的工作原理是……您可以肯定地编辑有问题的列(RecordingName),然后双击该列以外的任何地方,一切都很好。双击该列会出现问题。(对我来说)并不奇怪。您试图捕获双击,但同时也正在查看单击(通过PreviewMouseLeftButtonDown事件)。

我认为这是一个普遍的问题。有人可以建议我最好的处理方式吗?我绝对需要支持双击,但是也可以通过单击编辑来编辑RecordingName,这是很好的。

我还想通过右键单击RecordingName并选择重命名,然后使用F2选择它来支持编辑RecordingName。如果您转到Windows资源管理器,这就是您看到的行为。如果选择文件,然后在其上单击鼠标左键,则您处于编辑(重命名)模式。如果快速双击它,则文件将启动。如果右键单击或选择并单击F2,则可以对其进行重命名。

感谢您的帮助或想法。我粘贴了下面的代码。我确实尝试将其截断到最低限度。它仍然是很多代码。不管好坏,我都为控件本身使用了MVVM模型。

这是控件的xaml:

<UserControl x:Class="StackOverFlowExample.RecordingListControl"
         xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
         xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
         xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
         xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
          xmlns:local="clr-namespace:StackOverFlowExample"
         mc:Ignorable="d" 

         d:DesignHeight="300" d:DesignWidth="300">
<UserControl.Resources>
    <ResourceDictionary>

    <Style TargetType="{x:Type DataGridCell}">
        <EventSetter Event="PreviewMouseLeftButtonDown" Handler="DataGridCell_PreviewMouseLeftButtonDown"></EventSetter>
    </Style>
        <Style x:Key="CellViewStyle" TargetType="{x:Type Label}" BasedOn="{StaticResource {x:Type Label}}">
        <Style.Triggers>
            <Trigger Property="Validation.HasError" Value="true">
                <Setter Property="ToolTip"
                        Value="{Binding RelativeSource={RelativeSource Self},
                                Path=(Validation.Errors)[0].ErrorContent}"/>
                <Setter Property="BorderBrush" Value="Red" />
                <Setter Property="BorderThickness" Value="1" />
            </Trigger>
        </Style.Triggers>
    </Style>



        <Style TargetType="{x:Type DataGrid}" >
        <Setter Property="Foreground" Value="{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type local:RecordingListControl}}, Path=Foreground}" />

            <Style.Triggers>
                <Trigger Property="Validation.HasError" Value="true">
                    <Setter Property="ToolTip" Value="{Binding RelativeSource={RelativeSource Self}, Path=(Validation.Errors)[0].ErrorContent}"/>
                </Trigger> …
Run Code Online (Sandbox Code Playgroud)

wpf events datagrid mvvm

2
推荐指数
1
解决办法
2480
查看次数

log4net写入文件.如何打开权限

我很高兴在XP机器上使用log4net和我的WPF程序,并愉快地使用fileAppender FileAppender将日志消息写入c:\ log.txt.一切都好.但是,它不适用于Windows 7计算机.没有错误或任何东西,只是文件没有创建,更少记录.一个小小的研究表明它是Windows 7的文件权限问题(UAC),事实上,如果我以管理员身份运行可执行文件,它就可以工作.如果我只是点击它(即使我以管理员身份登录)它也不起作用,当我从Visual Studio启动时它不起作用.

问题:1.有人能指出一个例子,我要求允许写入一个且只有一个文件(C:\ log.txt).我已经看到一些示例,其中app.config配置为要求整个程序以管理员权限运行.这似乎有点矫枉过正,但我​​想它会起作用.2.有没有更好的方法将信息发送到日志文件?毕竟,也许C:在用户机器上不存在.我想我记得在Windows 7中使用"用户分区"的想法,但无论我做什么都必须在XP和Vista上工作.

谢谢你,戴夫

wpf log4net uac

1
推荐指数
1
解决办法
3332
查看次数

如何从另一个函数中捕获SML中的Exception?

我相信我对在SML中捕获异常有一些基本的误解.

我写了以下代码:

    fun my_g acc p =
    let 
    val r =  my_g acc
    in
    case p of
        Wildcard          => acc 
      | Variable x        =>    if List.exists (fn y => y = x) acc then raise NoAnswer else x::acc 
      | TupleP ps         => List.foldl (fn (p,i) => (my_g i p)) acc  ps
      | ConstructorP(_,p) => r p
      | _                 => acc
    end

(* val check_pat = fn : pattern -> bool *)          
 fun check_pat p =
   if my_g []  p <> …
Run Code Online (Sandbox Code Playgroud)

sml smlnj

1
推荐指数
1
解决办法
377
查看次数

我无法使用C#和Interop(P/Invoke)在Windows Vista中使用SetSystemTime

我很难让SetSystemTime在我的C#代码中工作.SetSystemtime是一个kernel32.dll函数.我正在使用P/invoke(interop)来调用它.SetSystemtime返回false,错误为"Invalid Parameter".我已经发布了以下代码.我强调GetSystemTime工作得很好.我已经在Vista和Windows 7上对此进行了测试.根据我发现的一些新闻组帖子,我已经关闭了UAC.没有不同.我已经做了一些搜索这个问题.我找到了这个链接:http: //groups.google.com.tw/group/microsoft.public.dotnet.framework.interop/browse_thread/thread/805fa8603b00c267

报告问题但似乎没有找到解决方案.请注意,还提到了UAC,但我不确定这是不是问题.还要注意这个绅士没有得到实际的Win32Error.

  1. 有人可以在XP上试用我的代码吗?
  2. 有人能告诉我我做错了什么以及如何解决它.如果答案是以某种方式以编程方式更改权限设置,我需要一个示例.我本以为关闭UAC应该涵盖那个.
  3. 我不需要使用这种特殊方式(SetSystemTime).我只是想引入一些"时钟漂移"来进行压力测试.如果有另一种方法,请告诉我.坦率地说,我很惊讶我需要使用Interop来改变系统时间.我原本以为有一种.NET方法.

非常感谢您的任何帮助或想法.安德鲁

码:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.InteropServices;

namespace SystemTimeInteropTest
{
    class Program
    {
        #region ClockDriftSetup
        [StructLayout(LayoutKind.Sequential)]
        public struct SystemTime
        {
            [MarshalAs(UnmanagedType.U2)]
            public short Year;
            [MarshalAs(UnmanagedType.U2)]
            public short Month;
            [MarshalAs(UnmanagedType.U2)]
            public short DayOfWeek;
            [MarshalAs(UnmanagedType.U2)]
            public short Day;
            [MarshalAs(UnmanagedType.U2)]
            public short Hour;
            [MarshalAs(UnmanagedType.U2)]
            public short Minute;
            [MarshalAs(UnmanagedType.U2)]
            public short Second;
            [MarshalAs(UnmanagedType.U2)]
            public short Milliseconds;
        }

        [DllImport("kernel32.dll")]
        public static extern void GetLocalTime(
        out SystemTime systemTime);

        [DllImport("kernel32.dll")]
        public static …
Run Code Online (Sandbox Code Playgroud)

c# interop systemtime

0
推荐指数
1
解决办法
3788
查看次数