Search Results

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

Page 8/25 | < Previous Page | 4 5 6 7 8 9 10 11 12 13 14 15  | Next Page >

  • Silverlight: AutoCompleteBox and TextWrapping

    - by Sven Sönnichsen
    How to enable TextWrapping in the AutoCompleteBox control of the SilverlightToolkit (November 2009)? There is no property to set the wrapping mode. So is there any workaround? Sven Here are more infos about my current problem: To me the AutoCompleteBox consists of a list which displays all possible values and a TextBox where I enter a search string and display a selected value. I want now, that the selected value in the TextBox wraps. So here is my current XAML, which uses the AutoCompleteBox in a DataGrid: <data:DataGrid x:Name="GrdComponents" ItemsSource="{Binding Path=Components}" AutoGenerateColumns="false" Margin="4" VerticalAlignment="Stretch" VerticalContentAlignment="Stretch" HorizontalScrollBarVisibility="Visible"> <data:DataGrid.Columns> <data:DataGridTemplateColumn Header="Component" Width="230"> <data:DataGridTemplateColumn.CellEditingTemplate > <DataTemplate> <input:AutoCompleteBox Text="{Binding Component.DataSource, Mode=TwoWay, ValidatesOnExceptions=True, NotifyOnValidationError=True}" Loaded="AcMaterials_Loaded" x:Name="Component" SelectionChanged="AcMaterial_SelectionChanged" IsEnabled="{Binding Component.IsReadOnly, Mode=OneWay, Converter={StaticResource ReadOnlyConverter}}" BindingValidationError="TextBox_BindingValidationError" ToolTipService.ToolTip="{Binding Component.Description}" IsTextCompletionEnabled="False" FilterMode="Contains" MinimumPopulateDelay="1" MinimumPrefixLength="3" ValueMemberPath="Description"> <input:AutoCompleteBox.ItemTemplate> <DataTemplate> <TextBlock Text="{Binding DescriptionTypeNumber}"/> </DataTemplate> </input:AutoCompleteBox.ItemTemplate> </input:AutoCompleteBox> </DataTemplate> </data:DataGridTemplateColumn.CellEditingTemplate> </data:DataGridTemplateColumn> </data:DataGrid.Columns> </data:DataGrid> The AutoCompleteBox uses different values for the list (DescriptionTypeNumer) and for the selected value (Description).

    Read the article

  • Adding a Combobox to a DataGrid in Silverlight

    - by bplus
    I can add a Combobox to a DataGrid using following xmal: <local:DataGridTemplateColumn Header="SomeHeader" Width="106" HeaderStyle="{StaticResource headerAlignRightStyle}" CellStyle="{StaticResource cellAlignRightStyle}"> <local:DataGridTemplateColumn.CellTemplate> <DataTemplate> <TextBlock Text="{Binding SomeProp}" Margin="4"/> </DataTemplate> </local:DataGridTemplateColumn.CellTemplate> <local:DataGridTemplateColumn.CellEditingTemplate> <DataTemplate> <ComboBox x:Name="SomeCombo" SelectionChanged="SomeCombo_SelectionChanged" ItemsSource="{Binding SomeList}" DisplayMemberPath="Name" /> </DataTemplate> </local:DataGridTemplateColumn.CellEditingTemplate> </local:DataGridTemplateColumn> However what I can't figure out is a sensible way to get the row that was combox is bound to. i.e. when handling the combobox SelectionChanged event I have no way of knowing what what row the combobox belongs to. Particularly I don't know what object in the DataGrid datasource that the combobox is refering to. Any help would be much appreciated.

    Read the article

  • Silverlight Toolkit ListBoxDragTarget Only One Way

    - by Tom Allen
    I've got a Silverlight 3 app that has two ListBoxes that I need to be able to drag items between. I've got the toolkit control working so that I can drag from ListBox lbA to ListBox lbB but i then can't drag the item from lbB back to lbA. <toolkit:ListBoxDragDropTarget mswindows:DragDrop.AllowDrop="True"> <ListBox x:Name="lbA" Style="{StaticResource ListBoxStyle}"> <ListBox.ItemTemplate> <DataTemplate> <TextBlock Text="{Binding DisplayMember}"/> </DataTemplate> </ListBox.ItemTemplate> </ListBox> </toolkit:ListBoxDragDropTarget> <toolkit:ListBoxDragDropTarget mswindows:DragDrop.AllowDrop="True"> <ListBox x:Name="lbB" Style="{StaticResource ListBoxStyle}" Width="350"> <ListBox.ItemTemplate> <DataTemplate> <TextBlock Text="{Binding DisplayMember}"/> </DataTemplate> </ListBox.ItemTemplate> </ListBox> </toolkit:ListBoxDragDropTarget> I'm binding lbA to an ObservableCollection of MyObject items which is a parent class for objects MyObjectA and MyObjectB (and there is a mix of ChildObjectA and ChildObjectB items). Is the one way behaviour I'm seeing due to binding to a collection MyObjects or something else i'm missing?

    Read the article

  • Confusion about WPF binding...

    - by Vladislav
    I am trying to bind a 2D array of buttons arranged in stackpanels to a 2D ObservableCollection... Yet, I'm afraid I don't understand something very elementary about binding. My XAML: <Window.Resources> <DataTemplate x:Key="ItemsAsButtons"> <Button Content="{Binding}" Height="100" Width="100"/> </DataTemplate> <DataTemplate x:Key="PanelOfPanels"> <ItemsControl ItemsSource="{Binding Path=DayNumbers}" ItemTemplate=" {DynamicResource ItemsAsButtons}"> <ItemsControl.ItemsPanel> <ItemsPanelTemplate> <StackPanel Orientation="Horizontal"/> </ItemsPanelTemplate> </ItemsControl.ItemsPanel> </ItemsControl> </DataTemplate> </Window.Resources> ... <ItemsControl x:Name="DaysPanel" Grid.ColumnSpan="7" Grid.Row="2" ItemTemplate="{DynamicResource PanelOfPanels}"/> My C# code: The backend: /// <summary> /// Window BE for Calendar.xaml /// </summary> public partial class Calendar : Window { private CalendarViewModel _vm; public Calendar() { InitializeComponent(); _vm = new CalendarViewModel(); this.DataContext = _vm; } } The ViewModel: class CalendarViewModel { CalendarMonth _displayedMonth; EventCalendar _calendar; public CalendarViewModel() { _displayedMonth = new CalendarMonth(); } public ObservableCollection<ObservableCollection<int>> DayNumbers { get { return _displayedMonth.DayNumbers; } } } I'm trying to populate the buttons with values from CalendarViewModel.DayNumbers - yet the buttons do not appear. I'm clearly doing something wrong with my binding.

    Read the article

  • Is there an MVVM-friendly way to swap views without value converters firing unnecessarily?

    - by DanM
    I thought what I was doing was right out of the Josh Smith MVVM handbook, but I seem to be having a lot of problems with value converters firing when no data in the view-model has changed. So, I have a ContentControl defined in XAML like this: <ContentControl Grid.Row="0" Content="{Binding CurrentViewModel}" /> The Window containing this ContentControl references a resource dictionary that looks something like this: <ResourceDictionary ...> <DataTemplate DataType="{x:Type lib_vm:SetupPanelViewModel}"> <lib_v:SetupPanel /> </DataTemplate> <DataTemplate DataType="{x:Type lib_vm:InstructionsPanelViewModel}"> <lib_v:InstructionsPanel /> </DataTemplate> </ResourceDictionary> So, basically, the two data templates specify which view to show with which view-model. This switches the views as expected whenever the CurrentViewModel property on my window's view-model changes, but it also seems to cause value converters on the views to fire even when no data has changed. It's a particular problem with IMultiValueConverter classes, because the values in the value array get set to DependencyProperty.UnsetValue, which causes exceptions unless I specifically check for that. But I'm getting other weird side effects too. This has me wondering if I shouldn't just do everything manually, like this: Instantiate each view. Set the DataContext of each view to the appropriate view-model. Give the ContentControl a name and make it public. Handle the PropertyChanged event for the window. In the event handler, manually set the Content property of the ContentControl to the appropriate view, based the CurrentViewModel (using if statements). This seems to work, but it also seems very inelegant. I'm hoping there's a better way. Could you please advise me the best way to handle view switching so that value converters don't fire unnecessarily?

    Read the article

  • How do I stop ValueConverters from firing when swapping the content of a ContentControl

    - by DanM
    I thought what I was doing was right out of the Josh Smith MVVM handbook, but I seem to be having a lot of problems with value converters firing when no data in the view-model has changed. So, I have a ContentControl defined in XAML like this: <ContentControl Grid.Row="0" Content="{Binding CurrentViewModel}" /> The Window containing this ContentControl references a resource dictionary that looks something like this: <ResourceDictionary ...> <DataTemplate DataType="{x:Type lib_vm:SetupPanelViewModel}"> <lib_v:SetupPanel /> </DataTemplate> <DataTemplate DataType="{x:Type lib_vm:InstructionsPanelViewModel}"> <lib_v:InstructionsPanel /> </DataTemplate> </ResourceDictionary> So, basically, the two data templates specify which view to show with which view-model. This switches the views as expected whenever the CurrentViewModel property on my window's view-model changes, but it also seems to cause value converters on the views to fire even when no data has changed. It's a particular problem with IMultiValueConverter classes, because the values in the value array get set to DependencyProperty.UnsetValue, which causes exceptions unless I specifically check for that. But I'm getting other weird side effects too. This has me wondering if I shouldn't just do everything manually, like this: Instantiate each view. Set the DataContext of each view to the appropriate view-model. Give the ContentControl a name and make it public. Handle the PropertyChanged event for the window. In the event handler, manually set the Content property of the ContentControl to the appropriate view, based the CurrentViewModel (using if statements). This seems to work, but it also seems very inelegant. I'm hoping there's a better way. Could you please advise me the best way to handle view switching so that value converters don't fire unnecessarily?

    Read the article

  • WPF Notify changes on object

    - by Erik Z
    I have a gridview were I define some columns, like this... <GridViewColumn.CellTemplate> <DataTemplate> <TextBlock Text="{Binding MyProp}" /> </DataTemplate> </GridViewColumn.CellTemplate> I bind my gridview to a collection and implemts INotifyPropertyChanged in the property MyProp. This works well and any changes of MyProp are reflected to the gridview. If I add another column that is bound to the object itself I dont get any notifications/updates. My code... <GridViewColumn.CellTemplate> <DataTemplate> <TextBlock Text="{Binding Converter={StaticResource myConverter}}"/> </DataTemplate> </GridViewColumn.CellTemplate> I think I need something like INotifyPropertyChanged for the object but I have no idea how to do this. Any suggestions?

    Read the article

  • ListBox and Listview problem

    - by Anu
    Hi, I have listbox in my applcation and corresponding coding.. XAML: <DataTemplate x:Key="menuItemTemplate"> <WrapPanel> <TextBlock Text="{Binding Path = Menu}" /> </WrapPanel> </DataTemplate> <ListBox x:Name="menubox" ItemsSource="{Binding}" ItemTemplate="{StaticResource menuItemTemplate}" Margin="0,5,0,0"> .CS : public void Add(string[] menu) { ItemList items = ItemList.Load(menu); DataContext = items; } It works fine.Later i add Listview for another purpose and i coded like the same way of listbox XAML: <DataTemplate x:Key="ListItemTemplate"> <WrapPanel> <TextBlock Text="{Binding Path = Title}" /> </WrapPanel> </DataTemplate> <ListView ItemsSource="{Binding}" ItemTemplate="{StaticResource ListItemTemplate}" Name="listView1" /> .cs coding: public void SetTree(string Title,int BoxNo ) { TreeList items1 = TreeList.Load(Title,BoxNo); DataContext = items1; } After adding Listview,what happended this ListView show data,but Listbox didnot show anything.When i click the listbox it perfectly executing the clicking event of listbox.Only problem it doesnot display the text.What can i do for that. Here i added corresponding list class pls see tht. namespace Tabcontrol { public class TreeList : Collection<TreeItems> { public int size; public TreeList() { size = 0; } public int Count { get { return size; } } public static TreeList Load(string pmenu,int Box) { TreeList result = new TreeList(); TreeItems item = TreeItems.Load(pmenu,Box); result.Add(item); return result; } } } The ItemList class also the same thing, only variable names are getting differred.

    Read the article

  • Using data binding on value which is a FrameworkElement

    - by JaredPar
    One of my data sources produces a collection of values which are typed to the following interface public interface IData { string Name { get; } FrameworkElement VisualElement { get; } } I'd like to use data binding in WPF to display a collection of IData instances in a TabControl where the Name value becomes the header of the tab and the VisualElement value is displayed as the content of the corresponding tab. Binding the header is straight forward. I'm stuck though on how to define a template which allows me to display the VisualElement value. I've tried a number of solutions with little success. My best attempt is as follows. <TabControl ItemsSource="{Binding}"> <TabControl.ItemTemplate> <DataTemplate> <Label Content="{Binding Name}"/> </DataTemplate> </TabControl.ItemTemplate> <TabControl.ContentTemplate> <DataTemplate> How do I display VisualElement here? </DataTemplate> </TabControl.ContentTemplate> </TabControl> I'm still very new to WPF so I could be missing the obvious here.

    Read the article

  • WPF: How can I KEEP the same ItemTemplate instance once its created ??

    - by Samir Sabri
    Hello, Here is a cinario: I have a ListView, with ItemsSource = ProjectModel.Instance.PagesModelsCollection; where PagesModelsCollection is an ObservableCollection In the ListView XAML part: <ListView.ItemTemplate> <DataTemplate x:Name="PagesViewDataTemplate"> <DataTemplate.Resources> <Style x:Key="PageHostStyle" TargetType="{x:Type p:KPage}"> </Style> </DataTemplate.Resources> <StackPanel x:Name="MarginStack" Margin="50,50,50,50" > <p:KPage x:Name="PageHost" > </p:KPage> </StackPanel> </DataTemplate> </ListView.ItemTemplate> The problem is the ITemTemplate is re-created each time we refresh the Items. So, if we have 100 Item in the list view, another 100 new ItemTemplate instance will be created if we refresh the items! As a result, if we add UIElements on one of the ItemTemplate intances, those added UIElements will be lost, because the old ITemTemplate is replaced with a new one! How can I KEEP the ItemTemplate instance once its created ??

    Read the article

  • Set ContentTemplate in CodeBehind: XamlParseException 2260 Error

    - by user362215
    Hi, I'd like to change the ContentTemplate of a ContentPresenter in the CodeBehind file. But if I run the Silverlight 4 application a XamlParseException with the error code 2260 occures. foreach (ContentPresenter item in Headers) { item.ContentTemplate = Parent.UnselectedHeaderTemplate; } if ((index >= 0) && (index < Headers.Count)) { ContentPresenter item0 = (ContentPresenter)Headers[index]; item0.ContentTemplate = Parent.SelectedHeaderTemplate; } If I do only the foreach code without the code in the "if", it works. And if I only do the code in the "if" without the foreach it works too. But togheter (the "if"-code and the foreach-code) it doesn't work. I have no idea why it doesn't work. The two templates look like this: <Setter Property="UnselectedHeaderTemplate"> <Setter.Value> <DataTemplate> <ContentControl Content="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=Content}" Margin="10,-10" FontSize="72" Foreground="#FF999999" CacheMode="BitmapCache"/> </DataTemplate> </Setter.Value> </Setter> <!-- SelectedHeader template --> <Setter Property="SelectedHeaderTemplate"> <Setter.Value> <DataTemplate> <ContentControl Content="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=Content}" Margin="10,-10" FontSize="72" Foreground="{TemplateBinding Foreground}" CacheMode="BitmapCache"/> </DataTemplate> </Setter.Value> </Setter> If you have an idea what problem is please tell me.

    Read the article

  • Set focus to a button in a new TabItem

    - by Jan
    I use a TabControl to display a list of items. The ItemView is a separate control I wrote. <TabControl SelectedItem="{Binding CurrentItem}" IsSynchronizedWithCurrentItem="True" ItemsSource="{Binding ItemList}"> <TabControl.ContentTemplate> <DataTemplate> <ctrls:ItemView/> </DataTemplate> </TabControl.ContentTemplate> <TabControl.ItemTemplate> <DataTemplate> <TextBlock Text="{Binding ShortItemDescription}"/> </DataTemplate> </TabControl.ItemTemplate> </TabControl> If the user presses a Button a new ViewModel is added to the list of ViewModels and the TabControl displays it as a new tab. After adding the new tab is selected. <Button Command="{Binding AddItemCommand}" Content="Add item"/> Inside of the new ViewModel is a button that needs to be focused each time a new tab is added. I have tried to use the FocusManager and the Initialized event in the ItemView but these are only called for the first time I add a new tab. <UserControl x:Class="ItemView" ... Initialized="ViewInitialized"> <Grid> ... <!-- Set focus to this button --> <Button Content="Search" Command="{Binding SearchCommand}" Name="SearchButton" Grid.Column="0" Grid.Row="0"/> </Grid> </UserControl> Any ideas?

    Read the article

  • How to make a cell in a datagrid readonly based the content on another cell in SL4?

    - by Nair
    I have two columns, the second column depends on the content on the first column. By default, the second columns is readonly. When I enter some valid value, I want the second column to become editable. To achive this, I created a cell template and cell edit template on the second column where back ground and read only bound to the first column. On load, the first column is null so my second columns comes correctly as read only. Following is Cell Template for second column, where the background color is set by based on the first column. <DataTemplate> <Grid> <Border Background="{Binding FristColumn,Converter={StaticResource ColorConverter}}"/> <TextBlock Text="{Binding SecondColumn, Converter={StaticResource NumberFormatter}}" HorizontalAlignment="Stretch" VerticalAlignment="Center" Margin="0"/> </Grid> </DataTemplate> Following is cell edit template for second column to make it editable <DataTemplate> <Grid> <TextBox Text="{Binding SecondColumn, Mode=TwoWay, Converter={StaticResource NumberFormatter}}" Margin="0" HorizontalAlignment="Right" IsReadOnly="{Binding FirstColumn, Converter={StaticResource readOnlyConverter}, ConverterParameter=FirstColumn}" Background="{Binding Depend,Converter={StaticResource ColorConverter}, ConverterParameter=FirstColumn}" /> </Grid> </DataTemplate> With these two in place, when enter the valid value in the first column, I was expecting the second column color to change but it does not. But If I double click on the cell then it behaves properly based on the first cell. Is there some thing I am missing?

    Read the article

  • WPF - List View Row Index and Validation

    - by abhishek
    Hi, I have a ListView with TextBoxes in second column. I want to validate that my text box does not contain a number if the third column(data_type) is "Text". I am unable to do the validation. I tried a few approaches. In one approach I try to handle the MouseDown event and am trying to get the Row number so that I can get the data_type value of that row. I want to us this value in the Validate method. I have been struggling for a week now. Would appreciate if anybody could help. <ControlTemplate x:Key="validationTemplate"> <DockPanel> <TextBlock Foreground="Red" FontSize="20">!</TextBlock> <AdornedElementPlaceholder/> </DockPanel> </ControlTemplate> <Style x:Key="textBoxInError" TargetType="{x:Type TextBox}"> <Style.Triggers> <Trigger Property="Validation.HasError" Value="true"> <Setter Property="ToolTip" Value="{Binding RelativeSource={x:Static RelativeSource.Self}, Path=(Validation.Errors)[0].ErrorContent}"/> </Trigger> </Style.Triggers> </Style> <DataTemplate x:Key="textTemplate"> <TextBox HorizontalAlignment= "Stretch" IsEnabled="{Binding XPath=./@isenabled}" Validation.ErrorTemplate="{StaticResource validationTemplate}" Style="{StaticResource textBoxInError}"> <TextBox.Text> <Binding XPath="./@value" UpdateSourceTrigger="PropertyChanged"> <Binding.ValidationRules> <local:TextBoxMinMaxValidation> <local:TextBoxMinMaxValidation.DataType> <local:DataTypeCheck Datatype="{Binding Source={StaticResource dataProvider}, XPath='/[@id=CustomerServiceQueueName]'}"/> </local:TextBoxMinMaxValidation.DataType> <local:TextBoxMinMaxValidation.ValidRange> <local:Int32RangeChecker Minimum="{Binding Source={StaticResource dataProvider}, XPath=./@min}" Maximum="{Binding Source={StaticResource dataProvider}, XPath=./@max}"/> </local:TextBoxMinMaxValidation.ValidRange> </local:TextBoxMinMaxValidation> </Binding.ValidationRules> </Binding > </TextBox.Text> </TextBox> </DataTemplate> <DataTemplate x:Key="dropDownTemplate"> <ComboBox Name="cmbBox" HorizontalAlignment="Stretch" SelectedIndex="{Binding XPath=./@value}" ItemsSource="{Binding XPath=.//OPTION/@value}" IsEnabled="{Binding XPath=./@isenabled}" /> </DataTemplate> <DataTemplate x:Key="booldropDownTemplate"> <ComboBox Name="cmbBox" HorizontalAlignment="Stretch" SelectedIndex="{Binding XPath=./@value, Converter={StaticResource boolconvert}}"> <ComboBoxItem>True</ComboBoxItem> <ComboBoxItem>False</ComboBoxItem> </ComboBox> </DataTemplate> <local:ControlTemplateSelector x:Key="myControlTemplateSelector"/> <Style x:Key="StretchedContainerStyle" TargetType="{x:Type ListViewItem}"> <Setter Property="HorizontalContentAlignment" Value="Stretch" /> <Setter Property="Template" Value="{DynamicResource ListBoxItemControlTemplate1}"/> </Style> <ControlTemplate x:Key="ListBoxItemControlTemplate1" TargetType="{x:Type ListBoxItem}"> <Border SnapsToDevicePixels="true" x:Name="Bd" Background="{TemplateBinding Background}" BorderBrush="{DynamicResource {x:Static SystemColors.ActiveBorderBrushKey}}" Padding="{TemplateBinding Padding}" BorderThickness="0,0.5,0,0.5"> <GridViewRowPresenter SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" VerticalAlignment="{TemplateBinding VerticalContentAlignment}"/> </Border> </ControlTemplate> <Style x:Key="CustomHeaderStyle" TargetType="{x:Type GridViewColumnHeader}"> <Setter Property="Background" Value="LightGray" /> <Setter Property="FontWeight" Value="Bold"/> <Setter Property="FontFamily" Value="Arial"/> <Setter Property="HorizontalContentAlignment" Value="Left" /> <Setter Property="Padding" Value="2,0,2,0"/> </Style> </UserControl.Resources> <Grid x:Name="GridViewControl" Height="Auto"> <Grid.RowDefinitions> <RowDefinition Height="*" /> <RowDefinition Height="34"/> </Grid.RowDefinitions> <ListView x:Name="ListViewControl" Grid.Row="0" ItemContainerStyle="{DynamicResource StretchedContainerStyle}" ItemTemplateSelector="{DynamicResource myControlTemplateSelector}" IsSynchronizedWithCurrentItem="True" ItemsSource="{Binding Source={StaticResource dataProvider}, XPath=//CONFIGURATION}"> <ListView.View > <GridView > <GridViewColumn Header="ID" HeaderContainerStyle="{StaticResource CustomHeaderStyle}" DisplayMemberBinding="{Binding XPath=./@id}"/> <GridViewColumn Header="VALUE" HeaderContainerStyle="{StaticResource CustomHeaderStyle}" CellTemplateSelector="{DynamicResource myControlTemplateSelector}" /> <GridViewColumn Header="DATATYPE" HeaderContainerStyle="{StaticResource CustomHeaderStyle}" DisplayMemberBinding="{Binding XPath=./@data_type}"/> <GridViewColumn Header="DESCRIPTION" HeaderContainerStyle="{StaticResource CustomHeaderStyle}" DisplayMemberBinding="{Binding XPath=./@description}" Width="{Binding ElementName=ListViewControl, Path=ActualWidth}"/> </GridView> </ListView.View> </ListView> <StackPanel Grid.Row="1"> <Button Grid.Row="1" HorizontalAlignment="Stretch" Height="34" HorizontalContentAlignment="Stretch" > <StackPanel HorizontalAlignment="Stretch" VerticalAlignment="Center" Orientation="Horizontal" FlowDirection="RightToLeft" Height="30"> <Button Grid.Row="1" Content ="Apply" Padding="0,0,0,0 " Margin="6,2,0,2" Name="btn_Apply" HorizontalAlignment="Right" VerticalContentAlignment="Center" HorizontalContentAlignment="Center" Width="132" IsTabStop="True" Click="btn_ApplyClick" Height="24" /> </StackPanel > </Button> </StackPanel > </Grid>

    Read the article

  • Choice of a deleted element at ListBox control

    - by Neir0
    Hi I have created a listbox control with following DataTemplate <DataTemplate x:Key="lb_Itemtemplate"> <DockPanel> <TextBlock Text="{Binding}" DockPanel.Dock="Left" /> <Button DockPanel.Dock="Right" Template="{StaticResource ButtonTemplate }" Width="20" Margin=" 0,1,1,10" >Delete </Button> <Button DockPanel.Dock="Right" Template="{StaticResource ButtonTemplate }" Width="20" Margin="0,1,1,10" >Highlight </Button> </DockPanel> </DataTemplate> <ListBox Name="listBox1" Grid.Column="0" Grid.Row="1" DataContext="{Binding ElementName=cb_fields, Path=SelectedItem}" ItemsSource="{Binding Path=PositiveXPathExpressions}" ItemTemplate="{StaticResource lb_Itemtemplate}" /> I want to delete element from "PositiveXPathExpressions" collection when user clicked on button "delete" but How i can decide which element i must to delete?

    Read the article

  • Focus In An ItemsControl

    - by Andrew
    I have an ItemsControl that uses a DataTemplate. The DataTemplate contains a TextBox, which can receive keyboard focus. I need to be able to move the keyboard focus from the currently focused TextBox in the DataTemplate to the next TextBox, as if the Tab key has been pressed. I've noticed that there is a UIElement.MoveFocus() method, but this begs the question as to which UIElement should be used to call the method. This is probably the reason why I haven't gotten this method to work for me... Any help would be really appreciated! Thanks, Andrew

    Read the article

  • Pass Data to Data Template Selector

    - by Michael Sync
    How do you guys pass the data (parameter) to DataTemplate Selector? The only one that I can think of is to use an attached property in DataTemplate Selector? Example: public class DisableWeekendsSelection : DataTemplateSelector { [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2211:NonConstantFieldsShouldNotBeVisible", Justification = "DependencyProperty")] public static readonly DependencyProperty Parameter = DependencyProperty.RegisterAttached("Parameter", typeof(ObservableCollection<Date>), typeof(DisableWeekendsSelection), new FrameworkPropertyMetadata(null, FrameworkPropertyMetadataOptions.BindsTwoWayByDefault)); public static ObservableCollection<Date> GetParameter(DependencyObject dp) { return dp.GetValue(Parameter) as ObservableCollection<Date>; } public static void SetParameter(DependencyObject dp, ObservableCollection<Date> value) { dp.SetValue(Parameter, value); } public override DataTemplate SelectTemplate(object item, DependencyObject container) { The problem with this approach is that I'm not able to get the value of Parameter in SelectTemplate method. Any suggestion would be appreciated. Thanks in advance.

    Read the article

  • Value of text box disapears - binding viewmodel to a tab (content control)

    - by Eli Perpinyal
    Based on the MVVM example by Josh Smith, I have implemented the multi tab option which binds to a different tab to a different view model using a simple datatemplate that binds a viewmodel to a view. <DataTemplate DataType="{x:Type fixtureVM:SearchViewModel}"> <SearchVw:SearchView/> </DataTemplate> The issue that I'm having, is when I switch tabs and then switch back again, the value in the textbox disappears. When I bind the Text in the textbox to a value in the ViewModel it does not disappear. This is fine, and I can overcome this but I am having another issue for example with the position of the scroll bar in a grid disappearing once the tab has lost focus. Why is the value disappearing? I'm assuming it is a WPF sub system task that cleans up resources!? how can I avoid this? I also feel it might be slowing down my app.

    Read the article

  • how to dynamically add button to SilverLight datagrid

    - by Grayson Mitchell
    I have a datagrid that I want to add a button/s to at runtime. I have managed to do this with the below code: DataGridTemplateColumn templateCol = new DataGridTemplateColumn(); templateCol.CellTemplate = (System.Windows.DataTemplate)XamlReader.Load( @"<DataTemplate xmlns='http://schemas.microsoft.com/client/2007' xmlns:x='http://schemas.microsoft.com/winfx/2006/xaml'> <Button Content='" + item.Value.Label + @"'/> </DataTemplate>"); _dataGrid.Columns.Add(templateCol); The problem is that I can't work out how to add a click event. I want to add a click event with a parameter corresponding to the row id...

    Read the article

  • LevelToVisibilityConverter in silverligt 4

    - by prince23
    <UserControl x:Class="SLGridImage.MainPage" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" mc:Ignorable="d" d:DesignHeight="300" d:DesignWidth="400" xmlns:sdk="http://schemas.microsoft.com/winfx/2006/xaml/presentation/sdk"> <UserControl.Resources> <local:LevelToVisibilityConverter x:Key="LevelToVisibility" /> </UserControl.Resources> <Grid x:Name="LayoutRoot" Background="White"> <sdk:DataGrid x:Name="dgMarks" CanUserResizeColumns="False" SelectionMode="Single" AutoGenerateColumns="False" VerticalAlignment="Top" ItemsSource="{Binding MarkCollection}" IsReadOnly="True" Margin="13,44,0,0" RowDetailsVisibilityMode="Collapsed" Height="391" HorizontalAlignment="Left" Width="965" VerticalScrollBarVisibility="Visible" > <sdk:DataGrid.Columns> <sdk:DataGridTemplateColumn> <sdk:DataGridTemplateColumn.CellTemplate> <DataTemplate> <Button x:Name="myButton" Click="myButton_Click"> <StackPanel Orientation="Horizontal"> <Image Margin="2, 2, 2, 2" x:Name="imgMarks" Stretch="Fill" Width="12" Height="12" Source="Images/test.png" VerticalAlignment="Center" HorizontalAlignment="Center" Visibility="{Binding Level, Converter={StaticResource LevelToVisibility}}" /> <TextBlock Text="{Binding Level}" TextWrapping="NoWrap" ></TextBlock> </StackPanel> </Button> </DataTemplate> </sdk:DataGridTemplateColumn.CellTemplate> </sdk:DataGridTemplateColumn> <sdk:DataGridTemplateColumn Header="Name" > <sdk:DataGridTemplateColumn.CellTemplate> <DataTemplate > <Border> <TextBlock Text="{Binding Name}" /> </Border> </DataTemplate> </sdk:DataGridTemplateColumn.CellTemplate> </sdk:DataGridTemplateColumn> <sdk:DataGridTemplateColumn Header="Marks" Width="80"> <sdk:DataGridTemplateColumn.CellTemplate> <DataTemplate> <Border> <TextBlock Text="{Binding Marks}" /> </Border> </DataTemplate> </sdk:DataGridTemplateColumn.CellTemplate> </sdk:DataGridTemplateColumn> </sdk:DataGrid.Columns> </sdk:DataGrid> </Grid> </UserControl> in .cs using System; using System.Collections.Generic; using System.Linq; using System.Net; using System.Windows; using System.Windows.Controls; using System.Windows.Documents; using System.Windows.Input; using System.Windows.Media; using System.Windows.Media.Animation; using System.Windows.Shapes; using System.Collections.ObjectModel; using System.ComponentModel; namespace SLGridImage { public partial class MainPage : UserControl { private MarksViewModel model = new MarksViewModel(); public MainPage() { InitializeComponent(); this.DataContext = model; } private void myButton_Click(object sender, RoutedEventArgs e) { } } public class MarksViewModel : INotifyPropertyChanged { public MarksViewModel() { markCollection.Add(new Mark() { Name = "ABC", Marks = 23, Level = 0 }); markCollection.Add(new Mark() { Name = "XYZ", Marks = 67, Level = 1 }); markCollection.Add(new Mark() { Name = "YU", Marks = 56, Level = 0 }); markCollection.Add(new Mark() { Name = "AAA", Marks = 89, Level = 1 }); } private ObservableCollection<Mark> markCollection = new ObservableCollection<Mark>(); public ObservableCollection<Mark> MarkCollection { get { return this.markCollection; } set { this.markCollection = value; OnPropertyChanged("MarkCollection"); } } public event PropertyChangedEventHandler PropertyChanged; public void OnPropertyChanged(string propName) { if (PropertyChanged != null) this.PropertyChanged(this, new PropertyChangedEventArgs(propName)); } } public class Mark { public string Name { get; set; } public int Marks { get; set; } public int Level { get; set; } } public class LevelToVisibilityConverter : System.Windows.Data.IValueConverter { #region IValueConverter Members public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture) { Visibility isVisible = Visibility.Collapsed; if ((value == null)) return isVisible; int condition = (int)value; isVisible = condition == 1 ? Visibility.Visible : Visibility.Collapsed; return isVisible; } public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture) { throw new NotImplementedException(); } #endregion } } when i run getting error The type 'local:LevelToVisibilityConverter' was not found. Verify that you are not missing an assembly reference and that all referenced assemblies have been built. what i am i missing here looking forward for an solution thank you

    Read the article

  • How not to include a Thumb in ListBoxItem selection

    - by Elad
    I have a collection of items. I am presenting the items in a WPF ListBox using DataTemplate. Part of the DataTemplate is a Thumb which is used for resizing and visually separating between items. The Thumb.Visibility is binded to a property of the item (for example, the last item doesn’t have a visible Thumb). The problem is that selecting an item in the ListBox selects the Thumb as well, as it is part of the ListBoxItem. The desired behavior is to select only the data without the Thumb. How is it possible to get this behavior? I don’t want to add items by code the ListBox or to handle the visibility of the Thumb manually. Currently I get all this from the DataTemplate.

    Read the article

  • Adding data (not only text) to a multi column ListView (WPF)

    - by user811804
    I am working on a WPF application in C# (.NET 4.0) where I have a ListView with a GridView that has two columns. I dynamically want to add rows (in code). My dilemma is that only the first column will have regular text added to it. The second column will have an object that includes a multi column Grid with TextBlocks. (see link http://imageshack.us/photo/my-images/803/listview.png/) If I do what you would normally do when you want to enter text in all columns (ie. DisplayMemberBinding) all I get in the second column is the text "System.Windows.Grid", which obviously isn't what I want. For reference if I just try to add the Grid object (with the TextBlocks) with the code listView1.Items.Add(grid1) (not using DisplayMemberBinding) the object gets added to the second column only (with the first column being blank) and not how it normally works with text where the same text ends up in all columns. I hope my question is detailed enough and any help with this would be much appreciated. EDIT: I have tried the following code, howeever every time I click the button to add a new row every single row gets updated with the same datatemplate. (ie. the second column always shows the same data on every row.) xaml: <Window x:Class="TEST.MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Name="AAA" Title="MainWindow" Height="350" Width="525" Loaded="Window_Loaded"> <Grid Name="grid1"> <Grid.ColumnDefinitions> <ColumnDefinition Width="374*" /> <ColumnDefinition Width="129*" /> </Grid.ColumnDefinitions> <Button Content="Button" Height="23" HorizontalAlignment="Left" Margin="21,12,0,0" Name="button1" VerticalAlignment="Top" Width="75" Grid.Column="1" Click="button1_Click" /> </Grid> code: public partial class MainWindow : Window { ListView listView1 = new ListView(); GridViewColumn viewCol2 = new GridViewColumn(); public MainWindow() { InitializeComponent(); Style style = new Style(typeof(ListViewItem)); style.Setters.Add(new Setter(ListViewItem.HorizontalContentAlignmentProperty, HorizontalAlignment.Stretch)); listView1.ItemContainerStyle = style; GridView gridView1 = new GridView(); listView1.View = gridView1; GridViewColumn viewCol1 = new GridViewColumn(); viewCol1.Header = "Option"; gridView1.Columns.Add(viewCol1); viewCol2.Header = "Value"; gridView1.Columns.Add(viewCol2); grid1.Children.Add(listView1); viewCol1.DisplayMemberBinding = new Binding("Option"); } private void Window_Loaded(object sender, RoutedEventArgs e) { } private void button1_Click(object sender, RoutedEventArgs e) { DataTemplate dataTemplate = new DataTemplate(); FrameworkElementFactory spFactory = new FrameworkElementFactory(typeof(Grid)); Random random = new Random(); int cols = random.Next(1, 6); int full = 100; for (int i = 0; i < cols; i++) { FrameworkElementFactory col1 = new FrameworkElementFactory(typeof(ColumnDefinition)); int partWidth = random.Next(0, full); full -= partWidth; col1.SetValue(ColumnDefinition.WidthProperty, new GridLength(partWidth, GridUnitType.Star)); spFactory.AppendChild(col1); } if (full > 0) { FrameworkElementFactory col1 = new FrameworkElementFactory(typeof(ColumnDefinition)); col1.SetValue(ColumnDefinition.WidthProperty, new GridLength(full, GridUnitType.Star)); spFactory.AppendChild(col1); } for (int i = 0; i < cols; i++) { FrameworkElementFactory text1 = new FrameworkElementFactory(typeof(TextBlock)); SolidColorBrush sb1 = new SolidColorBrush(); switch (i) { case 0: sb1.Color = Colors.Blue; break; case 1: sb1.Color = Colors.Red; break; case 2: sb1.Color = Colors.Yellow; break; case 3: sb1.Color = Colors.Green; break; case 4: sb1.Color = Colors.Purple; break; case 5: sb1.Color = Colors.Pink; break; case 6: sb1.Color = Colors.Brown; break; } text1.SetValue(TextBlock.BackgroundProperty, sb1); text1.SetValue(Grid.ColumnProperty, i); spFactory.AppendChild(text1); } if (full > 0) { FrameworkElementFactory text1 = new FrameworkElementFactory(typeof(TextBlock)); SolidColorBrush sb1 = new SolidColorBrush(Colors.Black); text1.SetValue(TextBlock.BackgroundProperty, sb1); text1.SetValue(Grid.ColumnProperty, cols); spFactory.AppendChild(text1); } dataTemplate.VisualTree = spFactory; viewCol2.CellTemplate = dataTemplate; int rows = listView1.Items.Count + 1; listView1.Items.Add(new { Option = "Row " + rows }); } }

    Read the article

  • Memory leak with WPF & ItemsControl (VB.NET)

    - by Matt H.
    I have an ItemsControl that uses a DataTemplate to display properties in my customClass that implements INotifyPropertyChanged... Pretty straightforward... Some items in the DataTemplate use CommandBindings (such as buttons), and a few have some code-behind (yuck). When I empty the ItemsControl and set all instances of customClass = Nothing , no memory is released from my program. This becomes a problem pretty quickly! Any idea where I should start looking? I've even gone so far as to completely traverse the visual tree of each DataTemplate instance and set each Visual = Nothing. I'm not really if that's supposed to have any effect though.

    Read the article

  • WPF Create Rectangle Tags on Image from DataBinding

    - by Noah
    I'm trying to add image tags to a WPF image and I'm not having much luck. I'd like to do it through databinding if at all possible. Can I set a resource with a DataTemplate to take care of this? Here's what I've been playing with to no avail: <Image Margin="25,4,14,46" Name="MainImage" Stretch="Uniform" MouseDown="MainImage_MouseDown" Grid.Row="1" HorizontalAlignment="Left" VerticalAlignment="Top" Source="{Binding Path=FileName}" > <Image.Resources> <DataTemplate DataType="{x:Type capp:CAPMeta}"> <Label Content="{Binding Path=TagText}"> </Label> </DataTemplate> </Image.Resources> </Image> Thanks!

    Read the article

  • generate Grid from template

    - by theXs
    Howdy, I've got another question regarding phone 7... I want to generate a couple of Grids in a stackpanel - since they all have the same layout I thought it would be a great idea to use DataTemplates ... But then I found that the GRID Object has no "DataTemplate" Property and now I'm kinda stuck ... the template which I use is the following: <DataTemplate x:Key="Speise"> <Grid> <TextBlock Height="36" Margin="8,43,104,0" TextWrapping="Wrap" Text="TextBlock" VerticalAlignment="Top"/> <TextBlock HorizontalAlignment="Right" Height="36" Margin="0,44,8,0" TextWrapping="Wrap" Text="TextBlock" VerticalAlignment="Top" Width="92"/> </Grid> </DataTemplate> The way I now thought of creating my objects is: Grid blubber = (Grid)this.Resources["Speise"]; But that is not working ... I think it's again a really short thing, but I have no clue of how to google for it :(

    Read the article

< Previous Page | 4 5 6 7 8 9 10 11 12 13 14 15  | Next Page >