controltemplate

Measuring controls created at runtime in WPF

只谈情不闲聊 提交于 2019-12-04 08:24:38
问题 I recognise this is a popular question but I couldn't find anything that answered it exactly, but I apologise if I've missed something in my searches. I'm trying to create and then measure a control at runtime using the following code (the measurements will then be used to marquee-style scroll the controls - each control is a different size): Label lb = new Label(); lb.DataContext= task; Style style = (Style)FindResource("taskStyle"); lb.Style = style; cnvMain.Children.Insert(0,lb); width =

Create ControlTemplate programmatically in WPF

落花浮王杯 提交于 2019-12-04 07:30:25
How can I programmatically set a button's template? Polygon buttonPolygon = new Polygon(); buttonPolygon.Points = buttonPointCollection; buttonPolygon.Stroke = Brushes.Yellow; buttonPolygon.StrokeThickness = 2; // create ControlTemplate based on polygon ControlTemplate template = new ControlTemplate(); template.Childeren.Add(buttonPolygon); // This does not work! What's the right way? //create button based on controltemplate Button button = new Button(); button.Template = template; So I need a way to set my Polygon as the button's template. Suggestions? Thanks. itowlson Officially, you should

WPF custom validator with tooltip

时光毁灭记忆、已成空白 提交于 2019-12-04 06:44:30
I'd like to create a custom validator template for my WPF app. I have a tooltip template: <ControlTemplate x:Key="ToolTipTemplate" TargetType="ToolTip"> <Grid Opacity="0.93" MaxWidth="200"> <Border BorderBrush="Black" BorderThickness="1,1,1,1" CornerRadius="2"> <Border.Background> <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0"> <GradientStop Color="#FFF5FAFE" Offset="0"/> <GradientStop Color="#FFE5EFF9" Offset="1"/> </LinearGradientBrush> </Border.Background> <Border.Effect> <DropShadowEffect Color="#FF393939" /> </Border.Effect> <TextBlock Margin="10,10,10,10" VerticalAlignment="Top

Create a visualtree off of a control template in code

陌路散爱 提交于 2019-12-04 05:47:30
This is a follow up question to a previous question, wich didn't really get me anywhere: deterministic and asynchronous field validation in WPF Since WPF doesn't support INotifyDataErrorInfo it seems, that I need to implement something like that myself (please correct me if I am wrong here). I need this because I want the ViewModel to trigger when to display special ErrorTemplates for certain fields (e.g. after the click of a button or after the end of a long running async validation operation or when the internal state changes in a way that certain fields suddenly become invalid). I am

VirtualizingStackPanel stops working when overriding the default control template for ScrollViewer

女生的网名这么多〃 提交于 2019-12-04 04:52:45
问题 I have a listbox with a lot of items which are expensive to render. However the VirtualizingStackPanel takes care of that by only rendering the visible items. I want to override the control template for ScrollViewer since the default one has grey rectangle between the horizontal and vertical scrollbar. I just copied the one provided by Microsoft (ScrollViewer ControlTemplate Example) which do not have the grey rectangle issue. This controltemplate however disables virtualization by giving the

WPF: Bind to command from ControlTemplate

让人想犯罪 __ 提交于 2019-12-04 04:03:00
I am trying to add a button to a custom ListView (MyListView) which triggers a command (MyCustomCommand) defined in MyListView. I have added the button (and a title text) by applying a ControlTemplate. The problem is that I have not found a way to trigger MyCustomCommand when clicking the button. What I eventually want to achieve is to open a Popup or ContextMenu where I can select which columns should be visible in the ListView. Here's my template source: <Style TargetType="local:MyListView"> <Setter Property="Template"> <Setter.Value> <ControlTemplate TargetType="local:MyListView"> <Border

How can I use an ElementName binding within a ControlTemplate?

社会主义新天地 提交于 2019-12-04 01:25:26
I have multiple TextBlocks which reference different elements in my application. My code works fine when used directly in the page. However, I want to create a ControlTemplate and a ContentControl to reduce the duplication of code. How can I pass a reference to an ElementName into the ControlTemplate from the ContentControl using TemplateBinding? The following code throws this error: "Cannot convert the value in attribute 'ElementName' to object of type 'System.String'. Object of type 'System.Windows.TemplateBindingExpression' cannot be converted to type 'System.String'. " In addition to the

Elegantly override style of ComboBox's ToggleButton in WPF

百般思念 提交于 2019-12-04 01:18:58
I have a question regarding how to elegantly override an arbitrary element deep inside a control's visual tree. I also have attempted to resolve it in a few different ways, but I've run into several problems with each. Usually when I try three different paths and fail at each one I go downstairs, have a coffee, and ask someone smarter than myself. So here I am. Specifics: I want to flatten the style of a combo box so that it will not draw attention to itself. I want it to be similar to Windows.Forms.ComboBox's FlatStyle I want it to look the same on Windows 7 and XP. Mainly, I want to change

Include a Button in a TextBox

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-03 16:04:26
I want to add a little Button , which removes all the text in the TextBox . Is it possible to put this "Remove"-Button into the TextBox (like in the iPhone Textboxs )? I hope after your help it looks like that: I played something with the controltemplate but didn't get the wished result. One way to solve this problem could be to use negative margins of the button, but i think that isn't a clean solution. Thank you! You can easily derive from textbox and create your own textbox with the functionality you want.That is the flexibility that wpf provides.See the link below http://davidowens

WPF - Use a ControlTemplate resource within a Style

情到浓时终转凉″ 提交于 2019-12-03 12:17:55
When creating a Style, is it possible to set the ControlTemplate property to a previously defined resource? For example, if I had the following in a ResourceDictionary: <ControlTemplate x:Key="MyControlTemplate" TargetType="{x:Type Button}"> ... </ControlTemplate> And then later wanted to use it in a Style like this: <Style x:Key="MyStyle" TargetType="{x:Type Button}"> <Setter Property="Template" Value="???"/> </Style> Is that possible? I believe this will work: <Style x:Key="MyStyle" TargetType="{x:Type Button}"> <Setter Property="Template" Value="{StaticResource MyControlTemplate}"/> </Style