Tag: wpf

WPF工具包,如何在C#中为datepicker控件应用日期格式?

WPF工具包,如何在C#中为datepicker控件应用日期格式?

从内存中显示RGBA图像

我有一个包含RGBA编码图像的C#字节数组。 在WPF中显示此图像的最佳方法是什么? 一种选择是从字节数组创建一个BitmapSource并将其附加到Image控件。 但是,创建BitmapSource需要一个用于RGBA32的PixelFormat,这在Windows中似乎不可用。 byte[] buffer = new byte[] { 25, 166, 0, 255, 90, 0, 120, 255 }; BitmapSource.Create(2, 1, 96d, 96d, PixelFormats.Bgra32, null, buffer, 4 * 2); 我绝对不想在我的字节数组中交换像素。

在WPF中禁用WebBrowser上的上下文菜单

我有一个WPF应用程序,它将在带有触摸屏的PC上的自助服务终端上运行。 应用程序以全屏模式运行,以隐藏操作系统。 在我的一个页面上,我有一个WebBrowser控件,允许用户查看一些网页(导航仅限于某些页面)。 由于计算机将被放置在公共场所,我不能让用户访问操作系统。 问题是,触摸屏允许右键单击Web浏览器,最终导致任务栏出现……不好……! 我一直试图在过去几天禁用该上下文菜单而没有太大的成功。 基本上我现在在的地方是: 添加了对SHDocVw.dll的COM引用以获取IWebBrowser2接口(需要禁用新窗口的启动。 [ComImport, InterfaceType(ComInterfaceType.InterfaceIsIUnknown)] [Guid(“6d5140c1-7436-11ce-8034-00aa006009fa”)] internal interface IServiceProvider { [return: MarshalAs(UnmanagedType.IUnknown)] object QueryService(ref Guid guidService, ref Guid riid); } static readonly Guid SID_SWebBrowserApp = new Guid(“0002DF05-0000-0000-C000-000000000046”); 获取IWEbBrowser2接口 IServiceProvider _serviceProvider = null; if (_browser.Document != null) { _serviceProvider = (IServiceProvider)_browser.Document; Guid _serviceGuid = SID_SWebBrowserApp; Guid _iid = typeof(SHDocVw.IWebBrowser2).GUID; SHDocVw.IWebBrowser2 _webBrowser […]

INotifyCollectionChanged:添加的项目不会出现在给定索引’0′

我正在制作一个可观察的课程。 Add方法工作正常。 但后来我试图调用Remove()方法我得到这个错误: “添加项目不会出现在给定索引’0’” 但是我将NotifyCollectionChangedAction枚举设置为Remove,如下面的代码所示。 public class ObservableOrderResponseQueue : INotifyCollectionChanged, IEnumerable { public event NotifyCollectionChangedEventHandler CollectionChanged; private List _list = new List(); public void Add(OrderResponse orderResponse) { this._list.Add(orderResponse); if (CollectionChanged != null) { CollectionChanged(this, new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Add, orderResponse, 0)); } } public void RemoveAt(int index) { OrderResponse order = this._list[index]; this._list.RemoveAt(index); if (CollectionChanged != null) { […]

确定哪个文本框已触发文本更改事件

我有许多通过代码动态创建的文本框。 我希望能够为所有文本框分配一个通用事件处理程序,以便更改文本,然后在处理程序中确定哪个文本框已触发事件。 我的代码是: txtStringProperty.TextChanged += TextBoxValueChanged; private void TextBoxValueChanged(object sender, RoutedEventArgs e) { string propertyName = // I would like the name attribute of the textbox here } 如果您需要更多信息,请告诉我。

如何返回SaveFileDialog的完整路径?

如何从SaveFileDialog获取完整路径字符串? SaveFileDialog.FileName只给我带扩展名的文件名。 我在MSDN上查看了SaveFileDialog ,但我没有看到任何属性。 我需要返回“C:\ Folder1 \ subFolder2 \ File004.sdf”而不仅仅是“File004.sf”

使WPF弹出窗口不受屏幕限制

Popup的默认行为是,如果它被放置在超出屏幕边缘的位置,Popup将重新定位自身。 有没有办法解决这个问题? 我有一个用户可以在屏幕上拖动的Popup。 但是,当它到达边缘时会卡住。 它会卡在边缘并停留在那里,直到鼠标被拖离边缘。 此外,我有两个显示器,当Popup被拖到边缘时,两个显示器共享我闪烁。 弹出窗口在两个监视器之间闪烁。

WPF CommandParameter MultiBinding值为null

我只是尝试将两个控件绑定为命令参数,并将它们作为object[]传递给我的命令。 XAML: GENERAL INFORMATION Test 命令: public ICommand ExpanderCommand { get { return new RelayCommand(delegate(object param) { var args = (object[])param; var content = (UIElement)args[0]; var button = (Button)args[1]; content.Visibility = (content.Visibility == Visibility.Visible) ? Visibility.Collapsed : Visibility.Visible; button.Content = (content.Visibility == Visibility.Visible) ? “-” : “+”; }); } } 转换器: public class MultiValueConverter : […]

如何将ItemsSource绑定到私有属性

如何将WPF和ItemsSource绑定到私有属性? public partial class ItemBuySellAddEdit : BasePage { private List Items { get; set; } } 表单加载时将填充项目列表。

如何在WPF中直接绘制位图(BitmapSource,WriteableBitmap)?

在GDI + Winforms中我会这样做: Bitmap b = new Bitmap(32,32); Graphics g = Graphics.FromImage(b); //some graphics code…` 如何使用DrawingContext在WPF中执行相同的操作?