user-controls 相关问题

UserControl是一个独立的可重用输入控件,允许用户与应用程序进行交互。用户控件可以是按钮,复选框,输入文本框,鼠标,键盘等。

如何隐藏 WPF 用户控件的标题和导航栏

我有一个简单的 wpf 应用程序,我在其中使用用户控件 我有一个简单的 wpf 应用程序,我在其中使用用户控件 <UserControl x:Class="DotNetGenetecWPF.TaskPreset" 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:AlertusGenetecModule.Alert" mc:Ignorable="d" d:DesignHeight="450" d:DesignWidth="400" Background="Black"> <Grid> 我想隐藏导航和标题栏,并希望应用程序看起来像这样 我不能使用 WindowStyle="None",因为它只与窗口相关,与用户控件无关。 尝试使用这些解决方案但没有任何效果 // walk up the tree to get the parent window FrameworkElement parent = this.Parent; while(parent != null && !parent is Window) { parent = parent.Parent; } // if window found, set style if(parent != null && parent is Window) { parent.WindowStyle = WindowStyle.None; } 知道我该怎么做吗? 谢谢,

回答 0 投票 0

Designer 弄乱了启用设计的 Custom UserControl 子容器的位置和大小

当我将此控件放在窗体上时,更改其大小和位置,保存并关闭窗体。打开后位置和大小不一样,但是在.Designer.cs里面就是这样设置的....

回答 1 投票 0

右键单击 Winforms 项目中的用户控件不显示属性窗口

我在 VS 2022 WinForms 项目中使用以下代码定义了一个用户控件 公共部分类 HScrollPerm : UserControl { [DllImport("user32.dll")] [返回:

回答 0 投票 0

在 web.config 中注册用户控件

在同一个项目中实现用户控件,我试图在 web.config 中引用它们,以便不在每个页面中包含 Register 子句。 注册一个单独的控件是可行的...

回答 1 投票 0

WPF 嵌套用户控件依赖绑定属性

我有一个使用 Prism 和 ViewModel 的 WPF 应用程序,我在使用具有自己的 CodeBehind 和 DependencyBinding 属性的嵌套 UserControl 时遇到问题。 使用此代码,

回答 1 投票 0

如何在 MenuStrip 上添加 CheckedListBox 和 Button?在 vs2019-vb.net 中过滤数据或排序

在这里输入图片描述 向社区和全世界问好 感谢您回答这个问题。 向社区和全世界问好 感谢您回答这个问题。

回答 0 投票 0

尝试向后移动时出现 Unity 3D 运动问题

我的播放器控制器在向前、向左和向右移动时工作正常。摄像机始终朝向玩家移动/旋转的方向,这很棒。 问题是当我按下...

回答 0 投票 0

如何为玩家动作添加碰撞? (团结)

我这里有一个代码,可以让玩家朝摄像机的方向移动。动作有效,但玩家穿过墙壁,我尝试向 p[层添加一个盒子对撞机,但是......

回答 1 投票 0

绑定在 MVVM WPF C# 应用程序中的用户控件内时找不到文本框

我有两个带有自定义验证的文本框,一个在主窗口中,一个在用户控件中。在这两种情况下,验证错误都会正确显示。我正在尝试仅启用“确定”按钮...

回答 1 投票 0

CoreWebView2_WebMessageReceived 没有被触发

我有一个带有简单按钮和文本框的 Angular Web 应用程序。 此应用程序将由 WPF 用户控件中包含的 WebView2 控件加载。 我正在为文本框文本发送一个 JSON 字符串

回答 1 投票 0

如何在设计时避免 XAML 代码中的“对象引用未设置到对象的实例”异常?

我自己设计的 wpf 用户控件有问题。 问题是我在设计时得到一个未设置为 XAML 代码中对象异常实例的对象引用,当我

回答 13 投票 0

在 WPF 应用程序中托管 EXE 应用程序

我有一个 WPF 应用程序,主窗口上有 4 个模块。当我单击其中一个模块时,它会打开该模块的详细信息窗口。我已经实现了 MVVM 模式来构建 WPF 应用程序...

回答 0 投票 0

在 MVVM WPF C# 应用程序中的用户控件内找不到文本框

我有两个带有自定义验证的文本框,一个在主窗口中,一个在用户控件中。在这两种情况下,验证错误都会正确显示。我正在尝试仅启用“确定”按钮...

回答 1 投票 0

ascx 用户控件表单对于某些输入数据是不可编辑的,因此需要隐藏指令如果是这样

我在遗留代码库中工作,其中存在带有控件的表单,这些控件分布在 asp.net 应用程序的 ascx 文件中。 表单将从数据库加载数据,对于某些特定情况...

回答 0 投票 0

让角色按照我给它的命令行动

当我在编码并试图弄清楚该怎么做时,我试图让角色移动到按钮顺序。 (上下左右)所以我做了我认为可行的事情但没有,所以我三...

回答 1 投票 0

如何在 WPF 中创建多个屏幕

我目前正在使用 MVVM 构建 WPF 应用程序,这就是我想要实现的目标。 所以,基本上当用户点击一个 Action 项目时,他们可以看到该项目的详细信息。一件物品可以...

回答 1 投票 0

如何使用户控件透明

我已经将 userControl 从 vb6 迁移到 vb.net,但我对它的透明度有疑问。 在vb6中,属性backstyle用于使控件透明,但在vb.net中,我找不到它....

回答 2 投票 0

Create a UserControl with a ViewModel

我想在 WinUI 3 中创建一个名为 ImageViewer 的用户控件,用于显示、遍历、添加和删除照片。 我的 UserControl 包含以下属性: 我收藏 我想在 WinUI 3 中创建一个名为 ImageViewer 的用户控件,它将显示、遍历、添加和删除照片。 我的用户控件包含以下属性: ICollectionPhotos 用于访问图片模型 DependencyProperty PhotosProperty 用于创建可以从 XAML 绑定的属性,如下所示: 注意:XAML 属性的名称不必与集合属性相同。 int CurrentPhotoIndex 用于跟踪显示的当前照片并阻止用户访问错误索引(尝试访问最后一张之后或第一张之前的照片) 字符串当前照片描述 用于跟踪当前照片的路径 ImageViewerViewModel ViewModel 包含数据和逻辑 由于 ImageViewer 是一个 UserControl,它继承自类 UserControl。为了在按下 Previous/Next/Add/Delete 按钮时能够更改照片,Photos Collection 和 Current* Properties 必须能够通知 UI 某些内容已更改(即当前照片已被删除,因此显示最后一张一)。 但是,我的理解是,一个类必须继承自 ObservableRecipient,从而对其数据(例如 Photos、CurrentPhotoIndex)使用 OnPropertyChanged 方法。我的想法是 Photos 集合不能在代码隐藏 (ImageViewer.xaml.cs) 中,而是在 ViewModel (ImageViewerViewModel) 中,然后我就可以遍历/添加/删除照片了。 我的问题是在示例中(我从中获得灵感)没有使用 ViewModel,我不知道如何将 DependencyProperty 数据设置为直接来自 ViewModel。 我的问题: 在 UserControl 中有一个 ViewModel 是个好主意吗? 如果 ViewModel 的使用是适用的并且是良好的实践/设计,我是否需要在代码隐藏和 ViewModel 中保留模型的集合,在适当的时候同步它们,还是只在 ViewModel 中? 如果使用 ViewModel 不是一个好主意(很难实现,还有另一种更简单或更好的方法)Photos 集合如何变成 Observable? 注意:我将它初始化为一个 ObservableCollection 但我无法正确看到图片。 我希望我的问题提出得很好。如果有人需要更多信息,我将非常乐意提供。 ImageViewer.xaml <!-- Copyright (c) Microsoft Corporation and Contributors. --> <!-- Licensed under the MIT License. --> <UserControl x:Class="MyApp.Desktop.UserControls.ImageViewer" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:local="using:MyApp.Desktop.UserControls" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:dxe="using:DevExpress.WinUI.Editors" mc:Ignorable="d"> <Grid Padding="12"> <Grid.RowDefinitions> <RowDefinition Height="*"/> <RowDefinition Height="Auto"/> </Grid.RowDefinitions> <StackPanel Orientation="Horizontal" Grid.Row="0"> <Grid> <Image Source="{x:Bind CurrentPhotoPath, Mode=TwoWay}" Stretch="Uniform"/> <Button Click="BtnPrevPhoto_Click" VerticalAlignment="Center" HorizontalAlignment="Left" Style="{StaticResource PreviousButtonStyle}"/> <Button Click="BtnNextPhoto_Click" VerticalAlignment="Center" HorizontalAlignment="Right" Style="{StaticResource NextButtonStyle}"/> </Grid> <StackPanel Orientation="Vertical" VerticalAlignment="Center" Margin="{StaticResource SmallLeftMargin}" Grid.Column="1"> <Button Click="BtnAddPhoto_Click" Margin="{StaticResource XXSmallBottomMargin}"> <FontIcon Glyph="&#xe109;" Style="{StaticResource SmallFontIconStyle}"/> </Button> <Button Click="BtnDeletePhoto_Click" Margin="{StaticResource XXSmallTopMargin}"> <FontIcon Glyph="&#xe107;" Style="{StaticResource SmallFontIconStyle}"/> </Button> </StackPanel> </StackPanel> <dxe:TextEdit x:Uid="/Products/TxtPhotoDescription" Text="{x:Bind CurrentPhotoDescription, Mode=TwoWay}" IsReadOnly="{x:Bind IsReadOnly, Mode=OneWay}" Style="{StaticResource FormSmallTextEditStyle}" Margin="{StaticResource SmallTopMargin}" HorizontalAlignment="Stretch" Grid.Row="1"/> </Grid> </UserControl> ImageViewer.xaml.cs // Copyright (c) Microsoft Corporation and Contributors. // Licensed under the MIT License. using System; using System.Collections; using System.Collections.Generic; using System.Collections.ObjectModel; using System.Linq; using CommunityToolkit.Mvvm.ComponentModel; using DevExpress.Mvvm.Native; using Microsoft.UI.Xaml; using Microsoft.UI.Xaml.Controls; using MyApp.Desktop.Helpers; using MyApp.Desktop.ViewModels.UserControls; using MyApp.Models.FileStorage; using MyApp.Models.Products; namespace ThemelioApp.Desktop.UserControls; public sealed partial class ImageViewer : UserControl { public static readonly DependencyProperty PhotosProperty = DependencyProperty.Register( "Photos", typeof(ICollection<Product_PhotoModel>), typeof(ImageViewer), new PropertyMetadata(null)); public ICollection<Product_PhotoModel> Photos { get => (ICollection<Product_PhotoModel>)GetValue(PhotosProperty); set => SetValue(PhotosProperty, value); } public static readonly DependencyProperty PhotosToDeleteProperty = DependencyProperty.Register( "PhotosToDelete", typeof(ICollection<long>), typeof(ImageViewer), new PropertyMetadata(null)); public ICollection<long> PhotosToDelete { get => (ICollection<long>)GetValue(PhotosToDeleteProperty); set => SetValue(PhotosToDeleteProperty, value); } public static readonly DependencyProperty IsReadOnlyProperty = DependencyProperty.Register( "IsReadOnlyProperty", typeof(bool), typeof(ImageViewer), new PropertyMetadata(null)); public bool IsReadOnly { get => (bool)GetValue(IsReadOnlyProperty); set => SetValue(IsReadOnlyProperty, value); } public int CurrentPhotoIndex { get; set; } private readonly string _noPhotoPath; public string CurrentPhotoPath { get; set; } public string CurrentPhotoDescription { get; set; } public ImageViewerViewModel ViewModel { get; } public ImageViewer() { InitializeComponent(); ViewModel = App.GetService<ImageViewerViewModel>(); Photos = new ObservableCollection<Product_PhotoModel>(); PhotosToDelete = new ObservableCollection<long>(); CurrentPhotoIndex = 0; _noPhotoPath = new Uri("ms-appx:///assets/Images/NoImage128x128.png").LocalPath; CurrentPhotoPath = Photos.Count == 0 ? _noPhotoPath : Photos.FirstOrDefault().Photo.LocalFilePath; CurrentPhotoDescription = ""; } private async void BtnAddPhoto_Click(object sender, RoutedEventArgs e) { var file = await FileStorageHelper.PickFile(FileStorageHelper.PickFileType.image, true); if (file == null) { return; } AddPhotoLocal(file.Path); } private async void BtnDeletePhoto_Click(object sender, RoutedEventArgs e) { RemovePhotoLocal(); } private void BtnNextPhoto_Click(object sender, RoutedEventArgs e) { Next(); } private void BtnPrevPhoto_Click(object sender, RoutedEventArgs e) { Previous(); } public void Next() { CurrentPhotoIndex++; UpdateCurrentPhoto(); } public void Previous() { CurrentPhotoIndex--; UpdateCurrentPhoto(); } public void AddPhotoLocal(string path) { Photos.Add( new Product_PhotoModel() { Photo = new FileStorageDetailedModel() { Description = "", LocalFilePath = path } }); } public void RemovePhotoLocal() { PhotosToDelete ??= new List<long>(); var toDelete = Photos.ElementAt(CurrentPhotoIndex); if (toDelete.Id > 0) { PhotosToDelete.Add(toDelete.Photo.Id); } Photos.Remove(toDelete); UpdateCurrentPhoto(); } public void UpdateCurrentPhoto() { if (CurrentPhotoIndex > Photos?.Count - 1) { CurrentPhotoIndex = (int)(Photos?.Count - 1); } else if (CurrentPhotoIndex < 0) { CurrentPhotoIndex = 0; } CurrentPhotoPath = Photos.ElementAt(CurrentPhotoIndex).Photo.LocalFilePath; CurrentPhotoDescription = Photos.ElementAt(CurrentPhotoIndex).Photo.Description; } } ImageViewerViewModel.cs(目前是空的,因为我无法让它工作) using System; using System.Collections.Generic; using System.Collections.ObjectModel; using System.Linq; using CommunityToolkit.Mvvm.ComponentModel; using Microsoft.UI.Xaml; using MyApp.Desktop.UserControls; using MyApp.Models.FileStorage; using MyApp.Models.Products; namespace MyApp.Desktop.ViewModels.UserControls; public class ImageViewerViewModel : ObservableRecipient { public ImageViewerViewModel() { } }

回答 0 投票 0

在运行时添加到 Windows Foam 的访问控制(文本框和组合框)

我正在将用户控件添加到我的主 Windows 泡沫中,用户控件由 Tablelayoutpanel 组成,其中包括 2 个组合框、1 个按钮和 4 个文本框,如下图所示: 我怎样才能访问...

回答 1 投票 0

使用 VBA SetFocus 的 MS Forms 焦点指示异常

默认情况下,当前具有焦点的 MS Forms 控件以虚线矩形突出显示 将控件的 TakeFocusOnClick 属性设置为 FALSE 可以防止这种情况;控件的外观...

回答 0 投票 0

© www.soinside.com 2019 - 2024. All rights reserved.