custom-controls

Setting Focus to a .NET UserControl…?

最后都变了- 提交于 2019-11-29 09:25:45
I'm creating a custom control derived from UserControl that I would like to set focus to. The custom control contains a ComboBox control and I draw some strings beside it. The ComboBox can receive focus, but I would like to be able to set focus to the UserControl itself. My OnPaint handler is set up to draw the control slightly differently if it has focus but I call CanFocus() from the parent form when I create my custom control and it returns false. Is there a property or something to set? Hans Passant UserControl will fight you tooth and nail to avoid getting the focus. It has code that

wpf custom control not recognized

我的未来我决定 提交于 2019-11-29 07:40:54
This is my first foray into custom controls, and it's not going well. I have a custom graph control derived from Canvas. namespace Grapher2 { public class SeriesManager : Canvas { public SeriesManager() { ... } } } It's defined in the same project and namespace as my app. I tried adding a reference to the control in XAML as follows: <Window x:Class="Grapher2.Window1" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:graph="clr-namespace:Grapher2" Title="Grapher" Width="800" Height="600"> <StackPanel Name="container"

Wpf custom control template - relative font size

和自甴很熟 提交于 2019-11-29 07:22:05
I am creating a custom WPF control that let's say for simplicity sake has a vertical stack panel with a "title" TextBlock, followed by a ContentPresenter. I want the font size for the "title" to be 5 Points LARGER than the size used in the content, which is inherited by whatever container the user places this control in. How can I specify a font size in the control template for the header element using a relative value without exposing a property like "TitleFontSize" to the user? I want do "add 5". I tried using a ScaleTransform on the header text block with mixed results (the text block

Using enum as a dependency property in WPF

假如想象 提交于 2019-11-29 07:08:30
I try to use enum type as a dependency property in my custom control, but always get an error: public enum PriceCategories { First = 1, Second = 2, Third = 3, Fourth = 4, Fifth = 5, Sixth = 6 } public static readonly DependencyProperty PriceCatProperty = DependencyProperty.Register("PriceCat", typeof(PriceCategories), typeof(CustControl), new PropertyMetadata(PriceCategories.First)); }; public PriceCategories PriceCat // here I get an error "Expected class, delegate, enum, interface or struct" { get { return (PriceCategories)GetValue(PriceCatProperty); } set { SetValue(PriceCatProperty, value)

A custom auto-sizing WPF Panel class

穿精又带淫゛_ 提交于 2019-11-29 04:14:39
问题 I'm trying to write a custom Panel class for WPF, by overriding MeasureOverride and ArrangeOverride but, while it's mostly working I'm experiencing one strange problem I can't explain. In particular, after I call Arrange on my child items in ArrangeOverride after figuring out what their sizes should be, they aren't sizing to the size I give to them, and appear to be sizing to the size passed to their Measure method inside MeasureOverride . Am I missing something in how this system is supposed

How to make WPF wrappanel child items to stretch?

北城余情 提交于 2019-11-29 03:32:42
I'd like to create an ItemsControl where child items are placed like a WrapPanel , but child Items should take as much space as it can. So that when the window size gets larger or smaller, the child items should stretch according to a certain width:height ratio. When the child items get added or removed from the ItemsControl 's ItemsSource , the WrapPanel should place linebreaks among items appropriately to keep child item's width:height ratio. Below is what I have so far. Is it possible to do this in Xaml? or should I create a custom control for this? Thanks in advance! <Window> <Grid>

BlackBerry - Creating custom Date Field

倾然丶 夕夏残阳落幕 提交于 2019-11-29 02:35:00
i want to create a field that looks like this ....can any one tell me how this could be done which field could i use where in i can select values by using the trackball/wheel or in case of storm i could slide... It could be simple Label or Bitmap Field extention, with navigation event handling. You will need to hold String array with values which will be changed in circle on horizontal navigation. If such custom Field is focused, draw Up and Down arrays. So, there will be one such Field for DayOfWeek, one for Month, one for DayOfMonth, one for Year. Place them all in HorizontalFieldManager,

WPF - Resource not loading from Generic.xaml

纵饮孤独 提交于 2019-11-29 02:27:30
问题 Themes\Generic.xaml: <ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"> <ResourceDictionary.MergedDictionaries> <ResourceDictionary Source="WPF Commons;component/Controls/Layout/Foo/FooItem.xaml" /> </ResourceDictionary.MergedDictionaries> </ResourceDictionary> Controls\Layout\Foo\FooItem.xaml: <Style TargetType="{x:Type l:FooItem}"> <Setter Property="Template"> <Setter.Value> <ControlTemplate

ASP.NET Custom Control - Unknown server tag

十年热恋 提交于 2019-11-29 00:54:35
I've made a custom control that inherits from a Literal control. When I try and use my control on a page a parsing error is thrown. I've added this to my web.config <configuration> <system.web> <pages> <controls> <add tagPrefix="one" namespace="myApplication.Controls"/> </controls> </pages> </system.web> </configuration> And I've added this to my page <%@ register namespace="myApplication.Controls" tagprefix="one" %> Neither of these have fixed the issue. I have a external assembly with some custom controls that work just fine within my project. As a workaround, I'm considering moving my

WPF User Controls vs Custom Controls

徘徊边缘 提交于 2019-11-29 00:15:55
问题 I am trying to creating a combobox with checkboxes on each line to allow multiple selecting. Would this be better as a User Control or Custom Control? I haven't created a control before so just looking for a little advice on what direction I need to head. Thanks. 回答1: I would say use a datatemplate. Like this: Looking for a WPF ComboBox with checkboxes It's a lot more simple than trying to create your own control. :) 回答2: UserControl (Composition) Composes multiple existing controls into a