user-controls 相关问题

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

在 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

使用“new”在 WPF C# 中创建一个重复的无模式窗口,该窗口使用 UserControl 镜像输入和显示原始内容

我为帖子的冗长标题道歉。我的目标是创建一组可重用的 XAML 元素(通过创建一个 UserControl)以显示通过文本手动输入的信息 ...

回答 0 投票 0

除了管理员组中的开发人员外,不向所有开发人员显示产品管道

我们有多个管道,它是这样的: ABC开发 ABC-qa ABC产品等 我们还有多个开发人员可以访问的其他管道和文件夹。 最近,我们发生了一个事件,开发者

回答 0 投票 0

在列表框中引用其他用户控件

我似乎无法解决的问题让我感到尴尬和恼火。我有一个 UserControls 的 ListBox,并且从一个 Button 事件中,我想操纵其他 UserControls...

回答 0 投票 0

控件和表单缺少图标和视图设计器选项在 vs2019 运行 SDK 项目与框架 4.7.2

到目前为止的总结答案:如果 csproj.user 文件存在,则表单和控件仅在设计器中打开。 问题故事: 我有 2 个控件,它们都继承自一个基本控件。 但是,缺少

回答 3 投票 0

c# wpf 通过用户名隐藏用户控件中的堆栈面板可见性

对于测试软件,我创建了一个窗口并将用户控件作为内容放入其中,现在我试图根据用户名更改用户控件中所有堆栈面板的可见性,我不工作...

回答 0 投票 0

只是想知道为什么这里的禁令这么容易

我正在迁移到 Quora,因为这个网站是垃圾。 无论我们多么努力,我们都无法从任何人那里得到任何答案。当我们能够做到时,我们会在这里帮助他人...... 我什至不在乎这个...

回答 0 投票 0

System.InvalidCastException 同时将用户控件添加到 CustomTaskPane

我正在尝试使用以下行在 Microsoft.Office.Tools.CustomTaskPane myCustomTaskPane 上添加用户控件: myUserControl = new IssueAddition(categoryList); myCustomTaskPane = this.

回答 2 投票 0

如何在 [ToolboxBitmap("MyResourcePictureFileName")] 上使用资源文件/路径

开发自定义控件,想放置自定义图标。这样做尝试在 [ToolboxBitmap("MyResourcePictureFileName")] 属性中使用解决方案资源文件,但图标未设置在...

回答 3 投票 0

Visual Studio 2022无法自动检测System.Web.UI.UserControl

首先我很抱歉,因为我的英语不好。我的项目有问题。当我创建新的用户控件时,在后面的代码 .cs System.Web.UI.UserControl 无法突出显示,并且我无法使用任何专业...

回答 0 投票 0

WPF 中的点几何

我正在创建直线和椭圆的几何图形,现在我想向该几何图形添加点。为此,我正在创建半径较小的椭圆。但问题是我正在对这个 geom 应用转换......

回答 1 投票 0

搞乱了 Windows 11 上 C 盘的安全设置

昨天我在摆弄安全设置,因为我无法在我的 C 驱动器根目录中粘贴任何内容..所以我右键单击 C 驱动器,属性,安全部分的高级设置......并更改......

回答 0 投票 0

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