Tag: user controls

从DataTemplate UWP绑定UserControl DP

我有一个显示小雕像的FlipView 。 小雕像包含其图像的路径 。 将此属性绑定到常规DataTemplate是可以的。 (以下代码工作正常) 但是当使用我的UserControl时,它不再起作用了: 从未设置过FigurinePath DP。 (如果我使用硬编码字符串,那很好。)这是输出中的错误: 错误:BindingExpression路径错误:’Com.Test.ViewModels.UserControl.FigurineStickerUserControlViewModel,eSmart.ViewModels,Version = 1.0.0.0,Culture = neutral,PublicKeyToken = null’上找不到’Path’属性。 BindingExpression:Path =’Path’DataItem =’Com.Test.ViewModels.UserControl.FigurineStickerUserControlViewModel,Test.ViewModels,Version = 1.0.0.0,Culture = neutral,PublicKeyToken = null’; target元素是’Com.Test.Views.FigurineStickerUserControl’(Name =’pageRoot’); target属性是’FigurinePath’(类型’对象’) 看起来DataTemplate尝试将Figurine分配为UserControl的DataContext,然后从我的UC的DataContext中检索属性。 但我的UC有自己的DataContext(它的ViewModel),我不想删除它。 不幸的是,对于WinRT / UWP,我没有使用Binding可以做的FindAncestor技巧。 我已经尝试过这个:( FlipFigurine是FlipView对象) 它不起作用。 即使将DP更改为对象并尝试以下操作也不起作用,DP的设置器永远不会被调用。 但是日志中没有错误。 FigurinePath=”{Binding SelectedItem, ElementName=FlipFigurine}” 有没有办法访问实际的Figurine对象,只需将其Path属性绑定到我的UC的FigurinePath属性?

如何将控件集中在WPF中的tabItem中

我在表单中有tabControl。 在其中一个tabItems中,我有文本框(myTextBox)。 我们称之为tabItem1。 当我在tabItem1中放置的这个文本框中写入内容时,我想在tabItem2中聚焦textbox(searchTextBox)。 我把这段代码放在了KeyDown中 tabItem2.Focus(); searchTextBox.Text = searchTextBoxTeropatik.Text; searchTextBox.Focus(); 我为此目的编写了这个小函数。 但是有一个大问题。 我按下了键 tabItem2获得焦点。 但是searchTextBox没有得到关注。(我的问题)

C#控件用DirectShow.Net显示摄像机video

我想使用DirectShow.Net从网络摄像头捕获流。 我可以使用哪种类型的UI控件来显示网络摄像头video捕获? 我看过一个使用Form的整个窗口的例子,但是我可以使用任何其他控件:Panel,PictureBox?

何时添加组件类与用户控件?

我有一个总的想法,并且有一些明显的情况,但是对我来说也有一些灰色区域 – 何时最好用于从组件扩展以及何时最好创建用户控件? 这与我试图解决的具体工作问题有关,但具体问题并不重要 – 这个问题的一般答案对我来说已经足够了。

Wpf自定义datepicker用户控件

我想创建一个用户控件来获取用户的日期。 它应该有三个文本框,一个用于年,月和日。 我不知道如何创建它。 代码背后 public partial class ChooseDateControl : UserControl { public static readonly DependencyProperty ValueProperty; public static readonly DependencyProperty YearProperty; public static readonly DependencyProperty MonthProperty; public static readonly DependencyProperty DayProperty; static ChooseDateControl() { ValueProperty = DependencyProperty.Register( “Value”, typeof(DateTime), typeof(ChooseDateControl), new FrameworkPropertyMetadata(DateTime.MinValue)); ValueProperty = DependencyProperty.Register( “Year”, typeof(int), typeof(ChooseDateControl), new FrameworkPropertyMetadata((int)0)); ValueProperty = DependencyProperty.Register( “Month”, typeof(int), […]

在代码而不是XAML中呈现UserControl

我想使用RenderTargetBitmap将UserControl呈现为位图,而不必为其编写XAML。 当我这样做时,我得到一张空白图片,我错过了关键一步吗? ValTool.Controls.VideoFisheyeOverlayControl vfoc = new Controls.VideoFisheyeOverlayControl(); vfoc.Width = (int)this.VideoContainer.ActualWidth; vfoc.Height = (int)this.VideoContainer.ActualHeight; vfoc.FieldsOfView=this.FieldsOfView; vfoc.CountLines = this.CountLines; vfoc.UpdateLayout(); vfoc.InvalidateVisual(); RenderTargetBitmap visual = new RenderTargetBitmap((int)this.VideoContainer.ActualWidth, (int)this.VideoContainer.ActualHeight, 96, 96, PixelFormats.Pbgra32); visual.Render(vfoc); var finalImage = BitmapFrame.Create(visual); // Encoding the RenderBitmapTarget as a PNG file. PngBitmapEncoder png = new PngBitmapEncoder(); png.Frames.Add(BitmapFrame.Create(finalImage)); using (Stream stm = File.Create(@”new.png”)) { png.Save(stm); }

如何在列表框WP8中绑定数据用户控件

我有一个用户控件。 它有一个TextBlock 。 我想在其中绑定Text 在MyUserControls.xaml.cs public partial class MyUserControl : UserControl { public MyUserControl() { InitializeComponent(); } public static readonly DependencyProperty TextProperty = DependencyProperty.Register( “Text”, typeof(string), typeof(MyUserControl), new PropertyMetadata(null)); public string Text { get { return (string)GetValue(TextProperty); } set { SetValue(TextProperty, value); } } } 当我绑定到ListBox它无法正常工作 和MainPage.xaml public partial class MainPage : PhoneApplicationPage { ObservableCollection […]

DrawToBitmap返回空白图像

我在winform应用程序中创建位图图像时遇到问题。 情况: 我有一个名为“ CanvasControl ”的UserControl ,它接受OnPaint方法作为我的Draw Pad应用程序的canvas。 在这个用户控件中,我有一个函数“ PrintCanvas() ”,它将创建UserControl到PNG文件的屏幕截图。 下面是PrintCanvas()函数: public void PrintCanvas(string filename = “sample.png”) { Graphics g = this.CreateGraphics(); //new bitmap object to save the image Bitmap bmp = new Bitmap(this.Width, this.Height); //Drawing control to the bitmap this.DrawToBitmap(bmp, new Rectangle(0, 0, this.Width, this.Height)); bmp.Save(Application.StartupPath + @”\ExperimentFiles\Experiment1″ + filename, ImageFormat.Png); bmp.Dispose(); } 这个用户控件( […]

NumericUpDown backcolor无法按预期工作

我最近需要编写一个Windows NumericUpDown控件的版本,它可以突出显示值是否是必需的。 它需要通过更改控件的背面颜色来完成此操作。 我认为这很简单,但是在尝试这样做时,我发现它有一个奇怪的副作用,就是不能完全控制所有控件。 使用下面的代码,我看到了这个: 当我在Windows窗体上放置一个控件,并更改BackColor属性(即蓝色)时 ,整个控件的数字部分会改变颜色。 或者,如果我改变了我的“IsMandatory”属性,则不是所有的背面颜色都改变了(它留下了边框) 。 因此,如果我将BackColor更改为蓝色,然后将IsMandatory设置为True,我将获得一个带蓝色边框的LightBlue控件(强制颜色) 。 鉴于它们都使用相同的代码,我不明白为什么应该这样。 非常接受的想法或解释。 public partial class MyNumericUpDown : NumericUpDown { private Boolean _isMandatory = false; private Color _mandatoryBackColor = Color.LightBlue; private Color _backColor = Color.FromKnownColor(KnownColor.Window); [DefaultValue(typeof(Color), “Window”), Description(“Overridden property”)] override public Color BackColor { get { return _backColor; } set { _backColor = value; MyResetColors(); […]

MVVMLight UserControl视图模型 – 为每个视图创建新的用户控件实例

我有一个用户控制我在其他视图中使用的患者列表。 但是,当我选择其中一个患者时,选择将传播到包含用户控件实例的所有视图。 如何让每个视图为每个视图实例化一个用户控件的新实例? 我正在使用c#