Search Results

Search found 603 results on 25 pages for 'datatemplate'.

Page 3/25 | < Previous Page | 1 2 3 4 5 6 7 8 9 10 11 12  | Next Page >

  • WPF Datatemplate + ItemsControl each item uses > 1 MB Memory?

    - by Matt H.
    Does that sound right to anyone???? I have an ItemsControl that displays data from a custom object that implements iNotifyPropertyChanged. The DataTemplate consists of: Border 3 buttons 5 textboxes An ellipse A Bindable RichTextBox (custom class that inherits from RichTextBox... so I could make Document a dependency property (to support binding)) Several grids and stackpanels for layout It uses: Styles (stored in a resource dictionary higher up the tree) Styles affect: colors, thicknesses, and text properties: which are data-bound to a "settings" class that implements iNotifyPropertyChanged, so the user can change display settings That's it! So what gives? I've also noticed that when I empty and remove the ItemsControl, memory isn't freed. over 5000 instances of "CommandBindingCollection" and "WeakReference" are CREATED (using ANTS profiler). And huge number of EffectiveValueEntry objects are created too. So really, what gives!!! :-) Thanks for your insight! Management needs this project soon but in its current state, it's unreleasable.

    Read the article

  • Creating a Silverlight DataTemplate in code

    - by Nick R
    How do I create a silverlight data template in code? I've seen plenty of examples for WPF, but nothing for Silverlight. Edit: Here's the code I'm now using this for, based on the answer from Santiago below. public DataTemplate Create(Type type) { return (DataTemplate)XamlReader.Load( @"<DataTemplate xmlns=""http://schemas.microsoft.com/client/2007""> <" + type.Name + @" Text=""{Binding " + ShowColumn + @"}""/> </DataTemplate>" ); } This works really nicely and allows me to change the binding on the fly.

    Read the article

  • How to define a DataTemplate in code?

    - by Asim Sajjad
    How can I create dataTemplate in code (using C#) and then add control to that DataTemplate ? <data:DataGrid.RowDetailsTemplate> <DataTemplate> <Border> <Border Margin="10" Padding="10" BorderBrush="SteelBlue" BorderThickness="3" CornerRadius="5"> <TextBlock Text="{Binding Description}" TextWrapping="Wrap" FontSize="10"> </TextBlock> </Border> </Border> </DataTemplate> </data:DataGrid.RowDetailsTemplate> I am using Sivlerlight.

    Read the article

  • Silverlight Update/Trigger IValueConverter in Listbox DataTemplate in a DataGrid

    - by LJ
    Hi I am building an application to display a datagrid bound to an ObservableCollection of Records, where each record has a Course Object and an ObservableCollection of Results Objects. The course is changed using an autocomplete box. The results collection is displayed in a Listbox with an IValueConverter implementation to change the colour of the ellipse template based on criteria of the course currently selected. It works great on loading, but subsequent updates to the course selection via the autocomplete does not trigger a recalculation/refresh of the value converter. Is there a way to trigger the refresh in XAML. I added UpdateSource=Property changed to the binding of the list box - but this caused a stack overflow (haha). Here is the code: <data:DataGrid x:Name="MyDatGrid"> <data:DataGrid.Columns> <data:DataGridTemplateColumn Header="Results"> <data:DataGridTemplateColumn.CellTemplate> <DataTemplate> <ListBox ItemsSource="{Binding ListOfResults}"> <ListBox.ItemsPanel> <ItemsPanelTemplate> <StackPanel Orientation="Horizontal"/> </ItemsPanelTemplate> </ListBox.ItemsPanel> <ListBox.ItemTemplate> <DataTemplate> <Ellipse Width="20" Height="20" Fill="{Binding Converter={StaticResource resultToBrushConverter} }" Stroke="Black" StrokeThickness="1" /> </DataTemplate> </ListBox.ItemTemplate> </ListBox> </DataTemplate> </data:DataGridTemplateColumn.CellTemplate> </data:DataGridTemplateColumn> <data:DataGridTemplateColumn Header="Course" > <data:DataGridTemplateColumn.CellTemplate> <DataTemplate> <Border> <input:AutoCompleteBox ItemsSource="{Binding Courses, Source={StaticResource coursesSource}}"/> </Border> </DataTemplate> </data:DataGridTemplateColumn.CellTemplate> I managed to subscribe to the LostFocus Event on the autocomplete box and reset a filter that I already have on the datagrid. But isn;t this very inefficient ? Refreshing the view on the datagrid does not have any effect in that method. Any steps in the right direction are greatly appreciated. Trying to prevent myself going anymore grey :) Had thoughts of getting the binding expression of the list in the grid and updating it, but no clue ? Thanks guys

    Read the article

  • Datatemplate binding

    - by Lasse O
    How can i achieve something like this: <ListView Name="OverviewTitlesListView" ItemsSource="{Binding OverviewTitlesCollection}"> <ListView.View> <GridView> <GridViewColumn Header="Index" Width="60" DisplayMemberBinding="{Binding TitleIndex}"/> <GridViewColumn Header="Start Time" Width="100" DisplayMemberBinding="{Binding StartTime}"/> <GridViewColumn Header="End Time" Width="100" DisplayMemberBinding="{Binding EndTime}"/> <GridViewColumn Header="Title Text" Width="550" DisplayMemberBinding="{Binding Text}"/> <GridViewColumn Header="Approved" Width="80"> <GridViewColumn.CellTemplate> <DataTemplate> <TextBlock Name="Test"/> <DataTemplate.Triggers> <Trigger Property="{Binding IsApproved}" Value="true"> <Setter TargetName="Test" Property="Text" Value="Approved"/> </Trigger> <Trigger Property="{Binding IsApproved}" Value="false"> <Setter TargetName="Test" Property="Text" Value="Not Approved"/> </Trigger> </DataTemplate.Triggers> </DataTemplate> </GridViewColumn.CellTemplate> </GridViewColumn> </GridView> </ListView.View> </ListView> When IsApproved property changes on my object in OverviewTitlesCollection i want to control the text of the TextBlock. How can i control this by triggers in my datatemplate?

    Read the article

  • Selecting the usercontrol to the relating datatemplate in mvvm

    - by msfanboy
    Hello, I have lets say a WeeklyViewUserControl.xaml and a DailyViewUserControl.xaml. Normally I used stuff like this to switch content: <DataTemplate DataType="{x:Type ViewModel:LessonPlannerViewModel}"> <View:LessonPlannerDailyUC/> </DataTemplate> This worked so far. But now I have still the WeeklyViewUC which uses 90 % of the LessonPlannerViewModel code so I want to make this additionally: <DataTemplate DataType="{x:Type ViewModel:LessonPlannerViewModel}"> <View:LessonPlannerWeeklyUC/> </DataTemplate> but this can not work, because from where does the ContentControl know that VM (LessonPlannerViewModel) should display a DailyViewUC or a WeeklyViewUC ? <ContentControl Content="{Binding VM}" />

    Read the article

  • How can I load combo box's data when it has been defined in DataTemplate codebehind ?

    - by Naseem
    Hi, In my silverlight application,I need to have dynamic columns in my DataGrid . So I had to create all the columns and their DataTemplate dynamically .When user wants to edit the column , a combo box will be displayed which has different values based on selected column. For creating each column I have wrote : foreach (var itemFilter in ProductFilterCollection) { DataGridTemplateColumn templateColumn = new DataGridTemplateColumn(); templateColumn.Header = itemFilter.Description.ToString(); templateColumn.CellTemplate = CreateCellTemplate(typeof(TextBlock), itemFilter.Description.ToString()); templateColumn.CellEditingTemplate = CreateEditingTemplate(typeof(ComboBox), itemFilter.Description.ToString()); grdTest.Columns.Add(templateColumn); } Here is the code for creating DataTemplate dynamically. public DataTemplate CreateCellTemplate(Type type, string strBinding) { return (DataTemplate)XamlReader.Load(@"<DataTemplate xmlns=""http://schemas.microsoft.com/client/2007""> <" + type.Name + @" Text=""{Binding " + strBinding + @"}""/> </DataTemplate>"); } public DataTemplate CreateEditingTemplate(Type type, string strBinding) { return (DataTemplate)XamlReader.Load(@"<DataTemplate xmlns=""http://schemas.microsoft.com/client/2007""> <" + type.Name + @" Loaded=""ddlTest_Loaded"" Tag=""{Binding " + strBinding + @"}""/> </DataTemplate>"); } I need to use Loaded="ddlTest_Loaded" in CreateEditingTemplate() ,in order to load the combo box . However it causes exception . When I remove Loaded event it's fine however the combo box is empty. How can I load the combo box when I define it in DataTemplate codebehind.

    Read the article

  • Binding DataTemplates (or another aproach)

    - by Bataglião
    Hi all, I'm having some troubles trying to dynamically generate content in WPF and after it bind data. I have the following scenario: TabControl - Dynamically generated TabItems through DataTemplate - inside TabItems, I have dynamic content generated by DataTemplate that I wish to bind (ListBox). The code follows: ::TabControl <TabControl Height="252" HorizontalAlignment="Left" Name="tabControl1" VerticalAlignment="Top" Width="458" Margin="12,12,12,12" ContentTemplate="{StaticResource tabItemContent}"></TabControl> ::The Template for TabControl to generate TabItems <DataTemplate x:Key="tabItemContent"> <Grid> <Grid.ColumnDefinitions> <ColumnDefinition Width="*" /> </Grid.ColumnDefinitions> <Grid.RowDefinitions> <RowDefinition Height="*" /> </Grid.RowDefinitions> <ListBox ItemTemplate="{StaticResource listBoxContent}" ItemsSource="{Binding}"> </ListBox> </Grid> </DataTemplate> ::The template for ListBox Inside each TabItem <DataTemplate x:Key="listBoxContent"> <Grid> <Grid.ColumnDefinitions> <ColumnDefinition Width="22"/> <ColumnDefinition Width="*" /> </Grid.ColumnDefinitions> <Image Grid.Column="0" Source="{Binding Path=PluginIcon}" /> <TextBlock Grid.Column="1" Text="{Binding Path=Text}" /> </Grid> </DataTemplate> So, when I try to do this on code inside a loop to create the tabitems: TabItem tabitem = tabControl1.Items[catIndex] as TabItem; tabitem.DataContext = plugins.ToList(); where 'plugins' is an Enumerable The ListBox is not bounded. I tried also to find the ListBox inside the TabItem to set the ItemSource property but no success at all. Someone have an idea on how to do that? Thanks in advance.

    Read the article

  • WPF - data binding trigger before content changed

    - by 0xDEAD BEEF
    How do i create trigger, which fires BEFORE binding changes value? How to do this for datatemplate? <ContentControl Content="{Binding Path=ActiveView}" Margin="0,95,0,0"> <ContentControl.Triggers> <--some triger to fire, when ActiveView is changing or has changed ?!?!? --> </ContentControl.Triggers> public Object ActiveView { get { return m_ActiveView; } set { if (PropertyChanging != null) PropertyChanging(this, new PropertyChangingEventArgs("ActiveView")); m_ActiveView = value; if (PropertyChanged != null) PropertyChanged(this, new PropertyChangedEventArgs("ActiveView")); } } How to do this for DataTemplate? <DataTemplate DataType="{x:Type us:LOLClass1}"> <ContentControl> <ContentControl.RenderTransform> <ScaleTransform x:Name="shrinker" CenterX="0.0" CenterY="0.0" ScaleX="1.0" ScaleY="1.0"/> </ContentControl.RenderTransform> <us:UserControl1/> </ContentControl> <DataTemplate.Triggers> <-- SOME TRIGER BEFORE CONTENT CHANGES--> <BeginStoryboard> <Storyboard> <DoubleAnimation Storyboard.TargetName="shrinker" Storyboard.TargetProperty="ScaleX" From="1.0" To="0.8" Duration="0:0:0.3"/> <DoubleAnimation Storyboard.TargetName="shrinker" Storyboard.TargetProperty="ScaleY" From="1.0" To="0.8" Duration="0:0:0.3"/> </Storyboard> </BeginStoryboard> </-- SOME TRIGER BEFORE CONTENT CHANGES--> </DataTemplate.Triggers> </DataTemplate> How to get notification BEFORE binding is changed? (i want to capture changing Visual component to bitmap and create sliding view animation)

    Read the article

  • Wrap or adorn wpf listview datatemplate

    - by Chris Cap
    I'm attempting to essentially wrap the contents of a DateTemplate in a listview gridview column with a border. What I want to know is if it's possible to supply an adorner that will surround that template so that I don't have to specify the border in every single datatemplate on every column (which is what I'm doing now). I've got something like this, but I know it's not right <Style TargetType="{x:Type ListBoxItem}"> <Setter Property="TemplateContent"> <Setter.Value> <ControlTemplate> <StackPanel> <Border BorderBrush="Green" BorderThickness="1"> <AdornedElementPlaceholder /> </Border> </StackPanel> </ControlTemplate> </Setter.Value> </Setter> </Style> This complains that Templatecontent is not a valid type. I've also tried with DataTemplate and that doesn't work either (understandably so). I know I could just create a DataTemplate, however the content for each column is different. At the very least, it binds to different fields. I'm wondering if there's a solution using a dynamic resource, but I don't know much about it. Thanks for your help EDIT: here's a sample of my listview <ListView ItemsSource="{Binding Path=OrderLines}" ItemContainerStyle="{StaticResource ResourceKey=ListViewItemContainerStyle}"> <ListView.View> <GridView> <GridViewColumn> <GridViewColumn.CellTemplate> <DataTemplate> <TextBox MaxWidth="30" Width="30" MaxLength="2" Text="{Binding Path=Quantity,ValidatesOnDataErrors=True}" /> </DataTemplate> </GridViewColumn.CellTemplate> </GridViewColumn> <GridView> <ListView.View> </ListView> Essentially I want to wrap that text box in the data template and any other items in additional columns.

    Read the article

  • Silverlight - Get the ItemsControl of a DataTemplate

    - by user208662
    Hello, I have a Silverlight application that is using a DataGrid. Inside of that DataGrid I have a DataTemplate that is defined like the following: <Grid x:Name="myGrid" Tag="{Binding}" Loaded="myGrid_Loaded"> <ItemsControl ItemsSource="{Binding MyItems}" Tag="{Binding}"> <ItemsControl.ItemTemplate> <DataTemplate> <StackPanel Orientation="Horizontal"> <StackPanel Orientation="Horizontal" Width="138"> <TextBlock Text="{Binding Type}" /> <TextBox x:Name="myTextBox" TextChanged="myTextBox_TextChanged" /> </StackPanel> </StackPanel> </DataTemplate> </ItemsControl.ItemTemplate> </ItemsControl> </Grid> When a user enters text into the TextBox, I have an event (myTextBox_TextChanged) that must be fired at this point. When that event gets fired, I would like to get the ItemsControl element that is the container for this TextBox. How do I get that ItemsControl from my event handler? Please note: Because the ItemsControl is in the DataTemplate of DataGrid, I don't believe I can just add an x:Name and reference it from my code-behind. Or is there a way to do that? Thank you!

    Read the article

  • Binding AutoCompleteBox inside DataTemplate

    - by Thiago
    I have the following AutoCompleteBox defined inside DataTemplate: <Window.Resources> <DataTemplate x:key="PaneTitleTemplate"> <Grid> <Grid.ColumnDefinitions> <ColumnDefinition /> <ColumnDefinition /> </Grid.ColumnDefinition> <ContentPresenter Content="{Binding}" /> <toolkit:AutoCompleteBox x:Name="InsertBox" ItemsSource="{???}" /> </Grid> </DataTemplate> </Window.Resources> ... <radRock:RadPane x:Name="pane1" TitleTemplate="{StaticResource PaneTitleTemplate}"/> Now I'd like to fill it with a list of strings, but I don't know which Binding should I use. The list of strings is an instance variable from the Window. What should I do?

    Read the article

  • Setting Canvas properties in an ItemsControl DataTemplate

    - by atsjoo
    I'm trying to databind to this ItemsControl: <ItemsControl ItemsSource="{Binding Path=Nodes, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"> <ItemsControl.ItemsPanel> <ItemsPanelTemplate> <Canvas /> </ItemsPanelTemplate> </ItemsControl.ItemsPanel> </ItemsControl> By using this DataTemplate, I'm trying to individually position my Node elements correctly: <DataTemplate DataType="{x:Type Model:EndNode}"> <Controls:EndNodeControl Canvas.Left="{Binding Path=XPos}" Canvas.Top="{Binding Path=YPos}" /> </DataTemplate> However, it's not working as expected. All my node elements are drawn on top of each other in the same position. Any suggestions on how to accomplish this?

    Read the article

  • Can a DataTemplate be a Page?

    - by dthrasher
    I'm using the MVVM pattern to create a WPF standalone application. My program compiles in Visual Studio 2008, but I frequently get warnings in the editor for my DataTemplates. In my MainWindow.xaml, I've defined the following DataTemplate: <DataTemplate DataType="{x:Type ViewModels:TagViewModel}"> <Views:TagView /> </DataTemplate> Where "TagView" is derived from a Page, rather than an ordinary UserControl. This causes the following message to appear every time I reload the designer in Visual Studio: "Could not create an instance of type 'TagView'. Yet the solution compiles fine and the program seems to work properly. Is this a bug in the Visual Studio 2008 editor? Or am I doing something wrong?

    Read the article

  • How can I bind the nested viewmodels to properties of a control

    - by Robert
    I used Microsoft's Chart Control of the WPF toolkit to write my own chart control. I blogged about it here. My Chart control stacks the yaxes in the chart on top of each other. As you can read in the article this all works quite well. Now I want to create a viewmodel that controls the data and axes in the chart. So far I'm able to add axes to the chart and show them in the chart. But I have a problem when I try to add the lineseries because it has one DependentAxis and one InDependentAxis property. I don't know how to assign the proper xAxis and yAxis controls to it. Below you see part of the LineSeriesViewModel. It has a nested XAxisViewModel and YAxisViewModel property. public class LineSeriesViewModel : ViewModelBase, IChartComponent { XAxisViewModel _xAxis; public XAxisViewModel XAxis { get { return _xAxis; } set { _xAxis = value; RaisePropertyChanged(() => XAxis); } } //The YAxis Property look the same } The viewmodels all have their own datatemplate. The xaml code looks like this: <UserControl.Resources> <DataTemplate x:Key="xAxisTemplate" DataType="{x:Type l:YAxisViewModel}"> <chart:LinearAxis x:Name="yAxis" Orientation="Y" Location="Left" Minimum="0" Maximum="10" IsHitTestVisible="False" Width="50" /> </DataTemplate> <DataTemplate x:Key="yAxisTemplate" DataType="{x:Type l:XAxisViewModel}"> <chart:LinearAxis x:Name="xAxis" Orientation="X" Location="Bottom" Minimum="0" Maximum="100" IsHitTestVisible="False" Height="50" /> </DataTemplate> <DataTemplate DataType="{x:Type l:LineSeriesViewModel}"> <!--Binding doesn't work on the Dependent and IndependentAxis! --> <!--YAxis XAxis and Series are properties of the LineSeriesViewModel --> <l:FastLineSeries DependentAxis="{Binding Path=YAxis}" IndependentAxis="{Binding Path=XAxis}" ItemsSource="{Binding Path=Series}"/> </DataTemplate> <Style TargetType="ItemsControl"> <Setter Property="ItemsPanel"> <Setter.Value> <ItemsPanelTemplate> <!--My stacked chart control --> <l:StackedPanel x:Name="stackedPanel" Width="Auto" Height="Auto" Background="LightBlue"> </l:StackedPanel> </ItemsPanelTemplate> </Setter.Value> </Setter> </Style> </UserControl.Resources> <Grid HorizontalAlignment="Stretch" VerticalAlignment="Stretch" ClipToBounds="True"> <!-- View is an ObservableCollection of all axes and series--> <ItemsControl x:Name="chartItems" ItemsSource="{Binding Path=View}" Focusable="False"> </ItemsControl> </Grid> This code works quite well. When I add axes they get drawn. But the DependentAxis and InDependentAxis of the lineseries control stay null, so the series doesn't get drawn. How can I bind the nested viewmodels to the properties of a control?

    Read the article

  • MVVM with animations (should I use VisualStateManager?)

    - by kennethkryger
    I've got a View.xaml with the following set in Resources-section: <DataTemplate DataType="{x:Type ViewModels:MyFirstViewModel}"> <Views:MyFirstView Content="{Binding}" /> </DataTemplate> <DataTemplate DataType="{x:Type ViewModels:MySecondViewModel}"> <Views:MySecondView Content="{Binding}"/> </DataTemplate> In the content of the View.xaml I have: <!-- SelectedMyViewModel is either set to MyFirstViewModel or MySecondViewModel --> <ContentControl Content="{Binding SelectedMyViewModel}" /> When the SelectedMyViewModel changes I'd like to have a animation, so that the current view is faded out and the new view is faded in... Somehow I feel this should be possible via the VisualStateManager - but I can't figure out how! This is a WPF 4.0 project...

    Read the article

  • MVVM Listbox DataTemplate SelectedItem

    - by StinkerPeter
    I am using a ListBox with a DataTemplate as shown below (xaml simplified and variable names changed). <ListBox ItemsSource="{Binding Path=ObservCollectionItems}" SelectedItem="{Binding Path=SelectedItemVar, Mode=TwoWay}"> <ListBox.ItemTemplate> <DataTemplate> <StackPanel> <TextBlock Text="{Binding SomeVar}" /> <Border> <StackPanel> <Button Content="String1" Command="{Binding DataContext.Command1} RelativeSource={RelativeSource FindAncestor, ListBox, 1}}" /> <Button Content="String2" Command="{Binding DataContext.Command2} RelativeSource={RelativeSource FindAncestor, ListBox, 1}}" /> </StackPanel> </Border> </StackPanel> </DataTemplate> <ListBox.ItemTemplate> </ListBox> I need the SelectedItemVar (dependency property) to update when I click on one of the buttons. SelectedItemVar is then used for the respective button's command. SelectedItemVar does update when I click on the TextBlock or the Border, but not when I click either button. I found a non-MVVM solution to this problem here. I do not want to add code in the file-behind to solve this, as they did in the link. Is there a clean solution that can be done in XAML. Beyond the non-MVVM solutions, I have not found anyone with this problem. I would have thought this was fairly common. Finally, I found this Command="{Binding DataContext.CommandName} RelativeSource={RelativeSource FindAncestor, ListBox, 1} for the Command binding. I do not fully understand what it is doing, but I do know that the command wasn't firing when I was binding directly to CommandName.

    Read the article

  • Accessing and manipulating lwpf listbox datatemplate elements

    - by black sensei
    Hello good people , i'm trying to achieve a functionality but i'm don't know how to start it. I'm using vs 2008 sp1 and i'm consuming a webservice which returns a collection (is contactInfo[]) that i bind to a ListBox with little datatemplate on it. <ListBox Margin="-146,-124,-143,-118.808" Name="contactListBox" MaxHeight="240" MaxWidth="300" MinHeight="240" MinWidth="300"> <ListBox.ItemTemplate> <DataTemplate> <TextBlock> <CheckBox Name="contactsCheck" Uid="{Binding fullName}" Checked="contacts_Checked" /><Label Content="{Binding fullName}" FontSize="15" FontWeight="Bold"/> <LineBreak/> <Label Content="{Binding mobile}" FontSize="10" FontStyle="Italic" Foreground="DimGray" /> <Label Content="{Binding email}" FontStyle="Italic" FontSize="10" Foreground="DimGray"/> </TextBlock> </DataTemplate> </ListBox.ItemTemplate> </ListBox> Every works fine so far. so When a checkbox is checked i'll like to access the information of the labels (either the) belonging to the same row or attached to it and append the information to a global variable for example (for each checkbox checked). My problem right now is that i don't know how to do that. Can any one shed some light on how to do that? if you notice Checked="contacts_Checked" that's where i planned to perform the operations. thanks for reading and helping out

    Read the article

  • WPF: how to find an element in a datatemplate from an itemscontrol

    - by EV
    Hi, I have the following problem: the application is using the custom itemscontrol called ToolBox. The elements of a toolbox are called toolboxitems and are custom contentcontrol. Now, the toolbox stores a number of images that are retrieved from a database and displayed. For that I use a datatemplate inside the toolbox control. However, when I try to drag and drop the elements, I don't get the image object but the database component. I thought that I should then traverse the structure to find the Image element. here's the code: Toolbox: public class Toolbox : ItemsControl { private Size defaultItemSize = new Size(65, 65); public Size DefaultItemSize { get { return this.defaultItemSize; } set { this.defaultItemSize = value; } } protected override DependencyObject GetContainerForItemOverride() { return new ToolboxItem(); } protected override bool IsItemItsOwnContainerOverride(object item) { return (item is ToolboxItem); } } ToolBoxItem: public class ToolboxItem : ContentControl { private Point? dragStartPoint = null; static ToolboxItem() { FrameworkElement.DefaultStyleKeyProperty.OverrideMetadata(typeof(ToolboxItem), new FrameworkPropertyMetadata(typeof(ToolboxItem))); } protected override void OnPreviewMouseDown(MouseButtonEventArgs e) { base.OnPreviewMouseDown(e); this.dragStartPoint = new Point?(e.GetPosition(this)); } public String url { get; private set; } protected override void OnMouseMove(MouseEventArgs e) { base.OnMouseMove(e); if (e.LeftButton != MouseButtonState.Pressed) { this.dragStartPoint = null; } if (this.dragStartPoint.HasValue) { Point position = e.GetPosition(this); if ((SystemParameters.MinimumHorizontalDragDistance <= Math.Abs((double)(position.X - this.dragStartPoint.Value.X))) || (SystemParameters.MinimumVerticalDragDistance <= Math.Abs((double)(position.Y - this.dragStartPoint.Value.Y)))) { string xamlString = XamlWriter.Save(this.Content); MessageBoxResult result = MessageBox.Show(xamlString); DataObject dataObject = new DataObject("DESIGNER_ITEM", xamlString); if (dataObject != null) { DragDrop.DoDragDrop(this, dataObject, DragDropEffects.Copy); } } e.Handled = true; } } private childItem FindVisualChild<childItem>(DependencyObject obj) where childItem : DependencyObject { for (int i = 0; i < VisualTreeHelper.GetChildrenCount(obj); i++) { DependencyObject child = VisualTreeHelper.GetChild(obj, i); if (child != null && child is childItem) return (childItem)child; else { childItem childOfChild = FindVisualChild<childItem>(child); if (childOfChild != null) return childOfChild; } } return null; } } here is the xaml file for ToolBox and toolbox item: <Style TargetType="{x:Type s:ToolboxItem}"> <Setter Property="Control.Padding" Value="5" /> <Setter Property="ContentControl.HorizontalContentAlignment" Value="Stretch" /> <Setter Property="ContentControl.VerticalContentAlignment" Value="Stretch" /> <Setter Property="ToolTip" Value="{Binding ToolTip}" /> <Setter Property="Template"> <Setter.Value> <ControlTemplate TargetType="{x:Type s:ToolboxItem}"> <Grid> <Rectangle Name="Border" StrokeThickness="1" StrokeDashArray="2" Fill="Transparent" SnapsToDevicePixels="true" /> <ContentPresenter Content="{TemplateBinding ContentControl.Content}" Margin="{TemplateBinding Padding}" SnapsToDevicePixels="{TemplateBinding UIElement.SnapsToDevicePixels}" ContentTemplate="{TemplateBinding ContentTemplate}"/> </Grid> <ControlTemplate.Triggers> <Trigger Property="IsMouseOver" Value="true"> <Setter TargetName="Border" Property="Stroke" Value="Gray" /> </Trigger> </ControlTemplate.Triggers> </ControlTemplate> </Setter.Value> </Setter> </Style> <Style TargetType="{x:Type s:Toolbox}"> <Setter Property="SnapsToDevicePixels" Value="true" /> <Setter Property="Focusable" Value="False" /> <Setter Property="Template"> <Setter.Value> <ControlTemplate> <Border BorderThickness="{TemplateBinding Border.BorderThickness}" Padding="{TemplateBinding Control.Padding}" BorderBrush="{TemplateBinding Border.BorderBrush}" Background="{TemplateBinding Panel.Background}" SnapsToDevicePixels="True"> <ScrollViewer VerticalScrollBarVisibility="Auto"> <ItemsPresenter SnapsToDevicePixels="{TemplateBinding UIElement.SnapsToDevicePixels}" /> </ScrollViewer> </Border> </ControlTemplate> </Setter.Value> </Setter> <Setter Property="ItemsPanel"> <Setter.Value> <ItemsPanelTemplate> <WrapPanel Margin="0,5,0,5" ItemHeight="{Binding Path=DefaultItemSize.Height, RelativeSource={RelativeSource AncestorType=s:Toolbox}}" ItemWidth="{Binding Path=DefaultItemSize.Width, RelativeSource={RelativeSource AncestorType=s:Toolbox}}" /> </ItemsPanelTemplate> </Setter.Value> </Setter> </Style> </ResourceDictionary> Example usage: <Toolbox x:Name="NewLibrary" DefaultItemSize="55,55" ItemsSource="{Binding}" > <ItemsControl.ItemTemplate> <DataTemplate> <StackPanel> <Image Source="{Binding Path=url}" /> </StackPanel> </DataTemplate> </ItemsControl.ItemTemplate> </Toolbox> The object that I get is a database object. When using a static resource I get the Image object. How to retrieve this Image object from a datatemplate? I though that I could use this tutorial: http://msdn.microsoft.com/en-us/library/bb613579.aspx But it does not seem to solve the problem. Could anyone suggest a solution? Thanks!

    Read the article

  • Can't use attached property on combobox inside hierarchical datatemplate WPF

    - by jesse_t_r
    I'm hoping to use an attached property to assign a command to the selection changed event of a combobox that is embedded inside a treeview. I'm attempting to set the attached property inside the hierchical data template for the tree but the command is not set and does not fire when the item in the combobox is changed. I've found that setting the attached property directly on a combobox outside of a datatemplate works fine; here is how I'm trying to set the property in the template: <HierarchicalDataTemplate x:Key="template1" ItemsSource="{Binding Path=ChildColumns}"> <Border Background="{StaticResource TreeItem_Background}" BorderBrush="Blue" BorderThickness="2" CornerRadius="5" Margin="2,5,5,2" HorizontalAlignment="Left" > <Grid> <Grid.ColumnDefinitions > <ColumnDefinition Width="Auto"/> <ColumnDefinition Width="*"/> <ColumnDefinition Width="*"/> </Grid.ColumnDefinitions> <Grid.RowDefinitions> <RowDefinition /> <RowDefinition /> </Grid.RowDefinitions> <TextBlock MinWidth="80" HorizontalAlignment="Left" Grid.Column="0" Margin="5,2,2,2" Grid.Row ="0" Text="{Binding Path=ColName}"/> <ComboBox Name="cboColType" Grid.Column="1" HorizontalAlignment="Right" ItemsSource="{Binding Source={StaticResource dataFromEnum}}" SelectedItem="{Binding Path=ColumnType}" Margin="2,2,2,2" local:ItemSelectedBehavior.ItemSelected="{Binding Path=LoadConfigCommand}" /> </Grid> </Border> </HierarchicalDataTemplate> I also tried creating a style <Style x:Key="childItemStyle" TargetType="{x:Type FrameworkElement}"> <Setter Property="local:ItemSelectedBehavior.ItemSelected" Value="{Binding Path=LoadConfigCommand}" /> </Style> and setting the itemcontainerstyle to the style in the hierarchical datatemplate..still no luck .. <HierarchicalDataTemplate> ... <ComboBox Name="cboColType" Grid.Column="1" HorizontalAlignment="Right" ItemsSource="{Binding Source={StaticResource dataFromEnum}}" SelectedItem="{Binding Path=ColumnType}" Margin="2,2,2,2" ItemContainerStyle={StaticeResource childItemStyle}" /> ... </HierarchicalDataTemplate> I'm still learning a lot about WPF so I'm assuming there is something particular about the hierchical datatemplate that is not allowing the attache dproperty to be set..I have found similar posts in the forums and tried to implement their solutions as above, but after a day of searching and experimenting wiht no luck I'm hoping some one has an idea about this...

    Read the article

  • Bind Grid.Row / Grid.Column inside a DataTemplate

    - by Thorsten79
    Hope this is not a dupe. I would like to be able to do the following in XAML: <DataTemplate DataType="{x:Type NewGACCTestApp:ButtonVM}"> <Button Grid.Column="{Binding GridColumn}" Grid.Row="{Binding GridRow}" Content="{Binding Path=Info}" /> </DataTemplate> The Content binding works fine but Grid.Column and Grid.Row simply don't exist in the produced object. Not even when I set them to some value without binding (like in Grid.Column="1"). I've snooped the application and saw that inside my grid nobody ever sets Grid.Column and Grid.Row. Any ideas?

    Read the article

  • Silverlight Question: How can I find the DataTemplate corresponding to an item in a ListBox

    - by morpheus
    I have two classes A & B, and a listbox. I assign listBox.ItemsSource equal to a collection of objects of type A. The listbox items are visualized using silverlight data templating, see http://msdn.microsoft.com/en-us/library/system.windows.datatemplate.aspx and http://www.codeproject.com/KB/WPF/UserControlAsDataTemplate.aspx for example. The listbox.ItemTemplate is a DataTemplate that uses class B to visualize the listbox items. Now, in my code-behind, inside any method of class B, if I do this.DataContext, it points to an object of type A. Thus, given an object of type B, I can find the corresponding object of type A. So far so good. My question is, given an object of type A, how can I navigate to the corresponding object of type B? Is this even possible in SL?

    Read the article

  • Silverlight: Binding to a LayoutRoot value from within a DataTemplate

    - by Rosarch
    I have a DataTemplate for a ListBox, where I have several controls that bind to an item. I would also like to bind to a value on LayoutRoot.DataContext. I'm unsure of how to do this. <!--LayoutRoot is the root grid where all page content is placed--> <StackPanel x:Name="LayoutRoot" Background="Transparent"> <ListBox ItemsSource="{Binding Items}"> <ListBox.ItemTemplate> <DataTemplate> <StackPanel> <TextBlock Text="{Binding}" /> <TextBlock Text="{Binding ElementName=LayoutRoot, Path=DataContext.Foo}" /> </StackPanel> </DataTemplate> </ListBox.ItemTemplate> </ListBox> </StackPanel> public partial class MainPage : PhoneApplicationPage { public string Foo { get { return "the moon"; } } private int startIndex = 1; private IList<string> _data = new List<string>() { "foo", "bar", "baz" }; public IList<string> Items { get { return _data; } } // Constructor public MainPage() { InitializeComponent(); LayoutRoot.DataContext = this; } } This doesn't work; only the _data items are displayed. The following binding errors appear in the Debug output: System.Windows.Data Error: BindingExpression path error: 'Foo' property not found on 'foo' 'System.String' (HashCode=1502598398). BindingExpression: Path='DataContext.Foo' DataItem='System.Windows.Controls.Border' (HashCode=78299055); target element is 'System.Windows.Controls.TextBlock' (Name=''); target property is 'Text' (type 'System.String').. System.Windows.Data Error: BindingExpression path error: 'Foo' property not found on 'bar' 'System.String' (HashCode=696029481). BindingExpression: Path='DataContext.Foo' DataItem='System.Windows.Controls.Border' (HashCode=78298703); target element is 'System.Windows.Controls.TextBlock' (Name=''); target property is 'Text' (type 'System.String').. System.Windows.Data Error: BindingExpression path error: 'Foo' property not found on 'baz' 'System.String' (HashCode=696029489). BindingExpression: Path='DataContext.Foo' DataItem='System.Windows.Controls.Border' (HashCode=78298694); target element is 'System.Windows.Controls.TextBlock' (Name=''); target property is 'Text' (type 'System.String').. Do I have a syntax error somewhere? Update I'm aiming for something that looks like this: foo the moon bar the moon baz the moon Instead, all I'm getting is: foo bar baz

    Read the article

< Previous Page | 1 2 3 4 5 6 7 8 9 10 11 12  | Next Page >