controltemplate

Difference between Control Template and DataTemplate in WPF

自作多情 提交于 2019-12-17 17:20:01
问题 What is difference between a ControlTemplate and a DataTemplate in WPF? 回答1: Typically a control is rendered for its own sake, and doesn't reflect underlying data. For example, a Button wouldn't be bound to a business object - it's there purely so it can be clicked on. A ContentControl or ListBox , however, generally appear so that they can present data for the user. A DataTemplate , therefore, is used to provide visual structure for underlying data, while a ControlTemplate has nothing to do

Silverlight 3: ListBox DataTemplate HorizontalAlignment

試著忘記壹切 提交于 2019-12-17 15:47:22
问题 I have a ListBox with it's ItemTemplate bound to a DataTemplate. My problem is I cannot get the elements in the template to stretch to the full width of the ListBox. <ListBox x:Name="listPeople" VerticalAlignment="Stretch" HorizontalAlignment="Stretch" Margin="0,0,0,0" Background="{x:Null}" SelectionMode="Extended" Grid.Row="1" ItemTemplate="{StaticResource PersonViewModel.BrowserDataTemplate}" ItemsSource="{Binding Mode=OneWay, Path=SearchResults}" > </ListBox> <DataTemplate x:Key=

How to access a WPF control located in a ControlTemplate?

微笑、不失礼 提交于 2019-12-17 10:57:28
问题 Usually, the WPF controls are declared in the .xaml files and not in the code behind (.xaml.cs files). However, sometimes I need to use some of those controls in code behind in order to manipulate them. How can I get the handle of such a control if it "resides" in the xaml file? 回答1: You can use the FindName() method of the ControlTemplate class. // Finding the grid that is generated by the ControlTemplate of the Button Grid gridInTemplate = (Grid)myButton1.Template.FindName("grid", myButton1

adding a header to a listbox's scrollviewer and keeping the virtualizingStackPanel (wp7)

帅比萌擦擦* 提交于 2019-12-14 01:28:59
问题 I want to add a header to my ListBoxes and I do this by using a template. The problem is that if I extend the ListBox's template it seems that the listbox's virtualizingstackpanel doesn't work anymore as expected: it loads all content before I can scroll it. I found some relevant questions in stackoverflow like this (VirtualizingStackPanel stops working when overriding the default control template for ScrollViewer) but the solution given there cannot be applied to WP7: I can't find the

How do I bind a command to e.g. the right mouse button in a ControlTemplate in WPF?

巧了我就是萌 提交于 2019-12-13 19:24:00
问题 I have a custom Control derived class and a view model to go with. The user can do several actions with this control, and I'm thinking it's best to implement these as RoutedCommand objects or ICommand derived objects in the view model so the ControlTemplates can bind to them. Binding a command to a button in one ControlTemplate should be straightforward, but how can I bind the command to e.g. the right mouse button in another ControlTemplate? Probably a MouseGesture is involved, but I'm

How do wpf control template triggers work?

删除回忆录丶 提交于 2019-12-13 06:39:27
问题 I have seen a control template for tab control...in http://www.codeproject.com/KB/WPF/WPFOutlookNavi.aspx Is this property triggers ? (Not data/event triggers) Is this trigger works this way - if TabStripPlacement is "Bottom"...all Setters will be executed ? <ControlTemplate.Triggers> <Trigger Property="TabStripPlacement" Value="Bottom"> <Setter Property="Grid.Row" TargetName="ContentPanel" Value="0" /> <Setter Property="Height" TargetName="RowDefinition0" Value="*" /> <Setter Property=

ControlTemplate Opacity not displayed like I want it to

左心房为你撑大大i 提交于 2019-12-13 06:03:03
问题 I have a Style defined for my DataGridCell <Style x:Key="MYDGCellStyle" TargetType="{x:Type DataGridCell}"> <Setter Property="OverridesDefaultStyle" Value="True" /> <Setter Property="Template" Value="{DynamicResource MYDGCellControlTemplate}" /> <Style.Triggers> <DataTrigger Binding="{Binding RelativeSource={RelativeSource Self}, Path=IsReadOnly}" Value="True"> <Setter Property="Background"> <Setter.Value> <SolidColorBrush Color="Gray" Opacity="0.3" /> </Setter.Value> </Setter> </DataTrigger>

How to create ControlTemplate from code behind in Windows Store App?

只谈情不闲聊 提交于 2019-12-13 04:14:38
问题 UPDATE 1 If ControlTemplate has binding, will XamlReader.Load(...) work ? <ControlTemplate TargetType="charting:LineDataPoint"> <Grid> <ToolTipService.ToolTip> <ContentControl Content="{Binding Value,Converter={StaticResource DateToString},ConverterParameter=TEST}"/> </ToolTipService.ToolTip> <Ellipse Fill="Lime" Stroke="Lime" StrokeThickness="3" /> </Grid> </ControlTemplate> I want to achieve this from code behind. <ControlTemplate> <Ellipse Fill="Green" Stroke="Red" StrokeThickness="3" /> <

Problem with the mouse click on toggleButton in WPF

左心房为你撑大大i 提交于 2019-12-12 12:05:07
问题 I made a custom control template that turns a groupbox into an expander (clicking on the header expands/collapses the content of the groupbox). It works fine except that mouse clicks don't always go through: sometimes it doesn't expand/collapse when you click on the header, esp. when you click inside the "o"s in the word "Colors". I organically thought it was caused by the text in the header trapping mouse clicks which prevent them from going through so I played around with the

How can I use an ElementName binding within a ControlTemplate?

冷暖自知 提交于 2019-12-12 08:24:35
问题 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