Search Results

Search found 169 results on 7 pages for 'itemscontrol'.

Page 4/7 | < Previous Page | 1 2 3 4 5 6 7  | Next Page >

  • Silverlight - how to render image from non-visible data bound user control?

    - by MagicMax
    Hello! I have such situation - I'd like to build timeline control. So I have UserControl and ItemsControl on it (every row represents some person). The ItemsControl contains another ItemsControl as ItemsControl.ItemTemplate - it shows e.g. events for the person arranged by event's date. So it looks as some kind of grid with dates as a column headers and e.g. peoples as row headers. ........................|.2010.01.01.....2010.01.02.....2010.01.03 Adam Smith....|......[some event#1].....[some event#2]...... John Dow.......|...[some event#3].....[some event#4]......... I can have a lot of persons (ItemsControl #1 - 100-200 items) and a lot of events occured by some day (1-10-30 events per person in one day) the problem is that when user scrolls ItemsControl #1/#2 it happened toooo sloooooowwww due to a lot of elements should be rendered in one time (as I have e.g. a bit of text boxes and other elements in description of particular event) Question #1 - how can I improve it? May be somebody knows better way to build such user control? I have to mention that I'm using custom Virtual panel, based on some custom Virtual panel implementation found somewhere in internet... Question #2 - I'd like to make image with help of WriteableBitmap and render data bound control to image and to show image instead of a lot of elements. Problem is that I'm trying to render invisible data bound control (created in code behind) and it has actualWidth/Height equals to zero (so nothing rendered). How can I solve it? Thank you very much for you help!

    Read the article

  • WPF Grid Column MaxWidth not enforced

    - by Trevor Hartman
    This problem stems from not being able to get my TextBlock to wrap. Basically as a last-ditch attempt I am setting MaxWidth on my container grid's columns. I was surprised to find that my child label and textbox still do whatever they want (bad children, BAD) and are not limited by my grid column's MaxWidth="200". What I'm really trying to do is let my TextBlock fill available width and wrap if necessary. So far after trying many variations of HorizontalAlignment="Stretch" on every known parent in the universe, nothing works, except setting an explicit MaxWidth="400" or whatever number on the TextBlock. This is not good because I need the TextBlock to fill available width, not be limited by some fixed number. Thanks! <ItemsControl> <ItemsControl.ItemsPanel> <ItemsPanelTemplate> <StackPanel /> </ItemsPanelTemplate> </ItemsControl.ItemsPanel> <ItemsControl.ItemTemplate> <DataTemplate> <Grid> <Grid.ColumnDefinitions> <ColumnDefinition MaxWidth="200" SharedSizeGroup="A" /> <ColumnDefinition MaxWidth="200" SharedSizeGroup="B" /> </Grid.ColumnDefinitions> <Label VerticalAlignment="Top" Margin="0 5 0 0" Grid.Column="0" Style="{StaticResource LabelStyle}" Width="Auto" Content="{Binding Value.Summary}" /> <TextBlock Grid.Column="1" Margin="5,8,5,8" FontWeight="Normal" Background="AliceBlue" Foreground="Black" Text="{Binding Value.Description}" HorizontalAlignment="Stretch" TextWrapping="Wrap" Height="Auto" /> </Grid> </DataTemplate> </ItemsControl.ItemTemplate> </ItemsControl>

    Read the article

  • How to Read some of the properties of the ItemSource when Laying out the Children?

    - by user275561
    Assume that I have the ItemSource bound and i am getting the data. Now what I want is this. The ItemSource will contain Data that tells where each button should be. For Example: The first Button could be at Left:200,Top:0, the Second could be Left:50 Top:20. </ItemsControl.Resources> <ItemsControl.ItemsPanel> <ItemsPanelTemplate> <Controls:MatrixCanvas /> </ItemsPanelTemplate> </ItemsControl.ItemsPanel> <ItemsControl.ItemTemplate> <DataTemplate> <item:CustomButton Height="{Binding btnSize}" Width="{Binding btnSize}" Style="{Binding bbColor,Converter={StaticResource ButtonStyleConverter}}" /> </DataTemplate> </ItemsControl.ItemTemplate> </ItemsControl> protected override Size ArrangeOverride(Size finalSize) { foreach (var child in Children) { //The child } return base.ArrangeOverride(finalSize); } The Child however is not giving me access to the Item that I want. Is their a good solution for this? Am I going about this the wrong way? The reason I am doing it like this is because their can be buttons added dynamically, removed, some buttons will need to move around etc..

    Read the article

  • DesignTime data not showing in Blend when bound against CollectionViewSource

    - by bitbonk
    I have datatemplate for a viewmodel where an itemscontrol is bound again a CollectionViewSource (to enable sorting in xaml). <DataTemplate x:Key="equipmentDataTemplate"> <Viewbox> <Viewbox.Resources> <CollectionViewSource x:Key="viewSource" Source="{Binding Modules}"> <CollectionViewSource.SortDescriptions> <scm:SortDescription PropertyName="ID" Direction="Ascending"/> </CollectionViewSource.SortDescriptions> </CollectionViewSource> </Viewbox.Resources> <ItemsControl ItemsSource="{Binding Source={StaticResource viewSource}}" Height="{DynamicResource equipmentHeight}" ItemTemplate="{StaticResource moduleDataTemplate}"> <ItemsControl.ItemsPanel> <ItemsPanelTemplate> <StackPanel Orientation="Horizontal" /> </ItemsPanelTemplate> </ItemsControl.ItemsPanel> </ItemsControl> </Viewbox> </DataTemplate> I have also setup the UserControl where all of this is defined to provide designtime data d:DataContext="{x:Static vm:DesignTimeHelper.Equipment}"> This is basically a static property that gives me an EquipmentViewModel that has a list of ModuleViewModels (Equipment.Modules). Now as long as I bind to the CollectionViewSource the designtime data does not show up in blend 3. When I bind to the ViewModel collection directly <ItemsControl ItemsSource="{Binding Modules}" I can see the designtime data. Any idea what I could do?

    Read the article

  • How can I use a parent content control from a sub binding?

    - by MGSoto
    I have the following code currently: <DataTemplate DataType="{x:Type vm:SectionViewModel}"> <ScrollViewer> <ItemsControl ItemsSource="{Binding ViewModels}"> <Grid/> </ItemsControl> </ScrollViewer> </DataTemplate> <DataTemplate DataType="{x:Type vm:StringViewModel}"> <Label Name="Left" Grid.Row="0" Grid.Column="0" Content="{Binding Label}"/> <TextBox Name="Right" HorizontalAlignment="Stretch" Grid.Row="0" Grid.Column="1" Text="{Binding Value}"/> </DataTemplate> The ViewModels property bound to SectionViewModel ItemsControl is a list of StringViewModel. I want to insert each StringViewModel into some sort of content control in the ItemsControl. Originally I just had each StringViewModel to make its own Grid, but that left things unaligned. I'd like to insert these items into some sort of content control in ItemsControl, it doesn't necessarily have to be a grid, but it should be within the ItemsControl. How can I do this? I'm also following MVVM, using MVVM Light.

    Read the article

  • How can I pass a reference to another control as an IValueConverter parameter?

    - by MKing
    I am binding some business objects to a WPF ItemsControl. They are displayed using a custom IValueConverter implementation used to produce the Geometry for a Path object in the DataTemplate as shown here: <ItemsControl x:Name="Display" Background="White" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" ItemsSource="{Binding ElementName=ViewPlaneSelector, Path=SelectedItem.VisibleElements}" > <ItemsControl.Resources> <!-- This object is just used to get around the fact that ConverterParameter can't be a binding directly (it's not a DependencyProperty on a DependencyObject --> <this:GeometryConverterData x:Key="ConverterParameter2" Plane="{Binding ElementName=ViewPlaneSelector, Path=SelectedItem}" /> <DataTemplate DataType="{x:Type o:SlenderMember}"> <Path Stroke="Blue" StrokeThickness=".5" Data='{Binding Converter={StaticResource SlenderMemberConverter}, ConverterParameter={StaticResource ConverterParameter2}}' ToolTip="{Binding AsString}"> </Path> </DataTemplate> </ItemsControl.Resources> </ItemsControl> Note that the items for the ItemsControl are drawn from the ViewPlaneSelector (a ComboBox) SelectedItem.VisibleElements property. I need that same ViewPlaneSelector.SelectedItem in the SlenderMemberConverter to figure out how to display this element. I'm trying to get a reference to it into the converter by creating the intermediate GeometryConverterData object in the Resources section. This object exists solely to get around the problem of not being able to bind directly to the ConverterParameter property (as mentioned in the comments). Here is the code for the GeometryDataConverter class: class GeometryConverterData : FrameworkElement { public static readonly DependencyProperty PlaneProperty = DependencyProperty.Register("Plane", typeof(ViewPlane), typeof(GeometryConverterData), null, ValidValue); public static bool ValidValue(object o){ return true; } public ViewPlane Plane { get{ return GetValue(PlaneProperty) as ViewPlane; }set{ SetValue(PlaneProperty, value); } } } I added the ValidValue function for debugging, to see what this property was getting bound it. It only and always gets set to null. I know that the ViewPlaneSelector.SelectedItem isn't always null since the ItemsControl has items, and it's items are drawn from the same property on the same object... so what gives? How can I get a reference to this ComboBox into my ValueConverter. Or, alternately, why is what I'm doing silly and overly complicated. I'm as guilty as many of sometimes getting it into my head that something has to be done a certain way and then killing myself to make it happen when there's a much cleaner and simpler solution.

    Read the article

  • WPF Repeater (like) control for collection source??

    - by Sonic Soul
    I have a WPF DataGrid bound to ObservableCollection. Each item in my collection has Property which is a List. In my row details pane, i would like to write out formatted textblocks for each item in this collection. The end result would be something equivalent to: <TextBlock Style="{StaticResource NBBOTextBlockStyle}" HorizontalAlignment="Right"> <TextBlock.Inlines> <Run FontWeight="Bold" Text="{Binding Path=Exchanges[0].Name}" /> <Run FontWeight="Bold" Text="{Binding Path=Exchanges[0].Price}" /> <LineBreak /> <Run Foreground="LightGray" Text="{Binding Path=Exchanges[0].Quantity}" /> </TextBlock.Inlines> </TextBlock> <TextBlock Style="{StaticResource NBBOTextBlockStyle}"> <TextBlock.Inlines> <Run FontWeight="Bold" Text="{Binding Path=Exchanges[1].Name}" /> <Run FontWeight="Bold" Text="{Binding Path=Exchanges[1].Price}" /> <LineBreak /> <Run Foreground="LightGray" Text="{Binding Path=Exchanges[1].Quantity}" /> </TextBlock.Inlines> </TextBlock> and so on 0-n times. I've tried using ItemsControl for this: <ItemsControl ItemsSource="{Binding Path=Exchanges}"> <DataTemplate> <Label>test</Label> </DataTemplate> </ItemsControl> however, this appears to be only meant for more static sources, as it throws the following exception (collection is not altered after creation): ItemsControl Operation is not valid while ItemsSource is in use. Access and modify elements with ItemsControl.ItemsSource instead Is there another way to achieve this?

    Read the article

  • Prism Commands - binding error when binding to list element ?

    - by Maciek
    I've got a ItemsControl (to be replaced by listbox) which has it's ItemsSource bound to an ObservableCollection<User> which is located in the view model. The View Model contains some DelegateCommand<T> delegates for handling commands (for instance UpdateUserCommand and RemoveUserCommand). All works fine if the buttons linked to those commands are placed outside of the DataTemplate of the control which is presenting the items. <ItemsControl ItemsSource="{Binding Users, Mode=TwoWay}" HorizontalContentAlignment="Stretch"> <ItemsControl.ItemTemplate> <DataTemplate> <Grid> <Grid.ColumnDefinitions> <ColumnDefinition Width="0.2*"/> <ColumnDefinition Width="0.2*"/> <ColumnDefinition Width="0.2*"/> <ColumnDefinition Width="0.2*"/> <ColumnDefinition Width="0.2*"/> </Grid.ColumnDefinitions> <TextBlock Grid.Column="0" Text="{Binding UserName}"/> <PasswordBox Grid.Column="1" Password="{Binding UserPass}"/> <TextBox Grid.Column="2" Text="{Binding UserTypeId}"/> <Button Grid.Column="3" Content="Update" cal:Click.Command="{Binding UpdateUserCommand}" cal:Click.CommandParameter="{Binding}"/> <Button Grid.Column="4" Content="Remove" cal:Click.Command="{Binding RemoveUserCommand}" cal:Click.CommandParameter="{Binding}"/> </Grid> </DataTemplate> </ItemsControl.ItemTemplate> </ItemsControl> What I'm trying to achieve, is : Have each row - generated by the ListView/ItemsControl - contain buttons to manage the item represented that particular row. During the runtime, the VS's output panel generated the following messages for each listbox element System.Windows.Data Error: BindingExpression path error: 'UpdateUserCommand' property not found on 'ModuleAdmin.Services.User' 'ModuleAdmin.Services.User' (HashCode=35912612). BindingExpression: Path='UpdateUserCommand' DataItem='ModuleAdmin.Services.User' (HashCode=35912612); target element is 'System.Windows.Controls.Button' (Name=''); target property is 'Command' (type 'System.Windows.Input.ICommand').. System.Windows.Data Error: BindingExpression path error: 'RemoveUserCommand' property not found on 'ModuleAdmin.Services.User' 'ModuleAdmin.Services.User' (HashCode=35912612). BindingExpression: Path='RemoveUserCommand' DataItem='ModuleAdmin.Services.User' (HashCode=35912612); target element is 'System.Windows.Controls.Button' (Name=''); target property is 'Command' (type 'System.Windows.Input.ICommand').. Which would imply that there are binding errors present. Is there any way to make this right? or is this not the way?

    Read the article

  • How to set focus to a brand new TextBox which was created as a result of a databinding in WPF?

    - by Mike
    Hi everyone, I have a WPF ItemsControl that is bound to an ObservableCollection. The XAML: <ItemsControl Name="mItemsControl"> <ItemsControl.ItemTemplate> <DataTemplate> <TextBox Text="{Binding Mode=OneWay}"></TextBox> </DataTemplate> </ItemsControl.ItemTemplate> </ItemsControl> The codebehind: private ObservableCollection<string> mCollection = new ObservableCollection<string>(); public MainWindow() { InitializeComponent(); this.mCollection.Add("Test1"); this.mCollection.Add("Test2"); this.mItemsControl.ItemsSource = this.mCollection; } private void Button_Click(object sender, RoutedEventArgs e) { this.mCollection.Add("new item!"); } When I click a button, it adds a new string to the databound ObservableCollection which triggers a new TextBox to appear. I want to give this new textbox focus. I've tried this technique from a related StackOverflow question but it always sets focus to the textbox before the newly created one. private void Button_Click(object sender, RoutedEventArgs e) { this.mCollection.Add("new item!"); // MoveFocus takes a TraversalRequest as its argument. TraversalRequest request = new TraversalRequest(FocusNavigationDirection.Previous); // Gets the element with keyboard focus. UIElement elementWithFocus = Keyboard.FocusedElement as UIElement; // Change keyboard focus. if (elementWithFocus != null) { elementWithFocus.MoveFocus(request); } } My need seems simple enough, but it's almost like the new textbox doesn't really exist until a slight delay after something is added to the ObservableCollection. Any ideas of what would work? Thanks! -Mike

    Read the article

  • How to determine if an item is the last one in a WPF ItemTemplate?

    - by Mike
    Hi everyone, I have some XAML <ItemsControl Name="mItemsControl"> <ItemsControl.ItemTemplate> <DataTemplate> <TextBox Text="{Binding Mode=OneWay}" KeyUp="TextBox_KeyUp"/> </DataTemplate> </ItemsControl.ItemTemplate> </ItemsControl> that's bound to a simple ObservableCollection private ObservableCollection<string> mCollection = new ObservableCollection<string>(); public MainWindow() { InitializeComponent(); this.mCollection.Add("Test1"); this.mCollection.Add("Test2"); this.mItemsControl.ItemsSource = this.mCollection; } Upon hitting the enter key in the last TextBox, I want another TextBox to appear. I have code that does it, but there's a gap: private void TextBox_KeyUp(object sender, KeyEventArgs e) { if (e.Key != Key.Enter) { return; } TextBox textbox = (TextBox)sender; if (IsTextBoxTheLastOneInTheTemplate(textbox)) { this.mCollection.Add("A new textbox appears!"); } } The function IsTextBoxTheLastOneInTheTemplate() is something that I need, but can't figure out how to write. How would I go about writing it? I've considered using ItemsControl.ItemContainerGenerator, but can't put all the pieces together. Thanks! -Mike

    Read the article

  • MVVM Light - master / child views and dependency properties

    - by Carl Dickinson
    I'm getting an odd problem when implementing a master / child view and custom dependency properties. Within my master view I'm binding the view model declaratively in the XAML as follows: DataContext="{Binding MainViewModelProperty, Source={StaticResource Locator}}" and my MainViewModel is exposing an observable collection which I'm binding to an ItemsControl as follows: <ItemsControl ItemsSource="{Binding Lists}" Height="490" Canvas.Top="10" Width="70"> <ItemsControl.ItemTemplate> <DataTemplate> <Canvas> <local:TaskListControl Canvas.Left="{Binding ListLeft}" Canvas.Top="{Binding ListTop}" Width="{Binding ListWidth}" Height="{Binding ListHeight}" ListDetails="{Binding}"/> </Canvas> </DataTemplate> </ItemsControl.ItemTemplate> </ItemsControl> TaskListControl in turn declares and bind to it's ViewModel and I've also defined a dependency property for the ListDetails property. The ListDetails property is not being set and if I remove the declarative reference to it's viewmodel the dependency property's callback does get fired. Is there a conflict with declaratively binding to viewmodels and definig dependency properties? I really like MVVM Light's blendability and want to perserve with this problem so any help would be apprectiated. If you'd like to receive the source for my project then please ask

    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

  • how to find a control inside ItemsPanelTemplate in wpf?

    - by kakopappa
    I am trying to access a Grid inside the DataTemplate while the ItemsControl is binded by ItemsSource. this is the full XMAL code, How do i find a certain element from outside? for (int i = 0; i < allViewControl.Items.Count; i++) { var container = allViewControl.ItemContainerGenerator.ContainerFromItem(allViewControl.Items[i]) as FrameworkElement; var grid = allViewControl.ItemTemplate.FindName("grid", container) as DataGrid; } i found this always returning null ? <ScrollViewer Grid.Row="0" HorizontalScrollBarVisibility="Disabled" VerticalScrollBarVisibility="Auto"> <ItemsControl x:Name="allViewControl" Focusable="False" HorizontalContentAlignment="Center" Grid.IsSharedSizeScope="true" ItemsSource="{Binding AllClassCharacters}" ItemTemplate="{StaticResource CharacterViewModelTemplate}" > <ItemsControl.ItemsPanel> <ItemsPanelTemplate> <Extensions:AnimatedWrapPanel IsItemsHost="true" /> </ItemsPanelTemplate> </ItemsControl.ItemsPanel> </ItemsControl> </ScrollViewer> <DataTemplate x:Key="CharacterViewModelTemplate" DataType="{x:Type ViewModel:CharacterViewModel}"> <Grid x:Name="grid" Width="200" Height="Auto" MinHeight="115" Margin="1" MinWidth="130" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" RenderTransformOrigin="0.5,0.5" Background="#66000000" > <Grid.RowDefinitions> <RowDefinition Height="70"/> <RowDefinition Height="*"/> </Grid.RowDefinitions> <Grid.ColumnDefinitions> <ColumnDefinition Width="*" /> <ColumnDefinition Width="*" /> </Grid.ColumnDefinitions> <ProgressBar x:Name="playerProgressBar" VerticalAlignment="Top" Background="Transparent" Height="5" Width="Auto" Value="0" Visibility="Collapsed" Grid.Column="0" Grid.Row="0" Grid.ColumnSpan ="2" Grid.RowSpan="2" Foreground="White" BorderThickness="0" Style="{DynamicResource ProgressBarStyle1}" /> </Grid>

    Read the article

  • Silverlight MVVM MEF ViewInjection

    - by silverfighter
    Hi all, since my title is buzzword compliant I hope I will get lots of answers to my question or any pointers to the right direction. OK what I usually do is have a ViewModel which contains a list of ViewModels itself. public class MasterViewModel { public ObservableCollection<DetailViewModel> DetailViewModels { get; set; } public DetailViewModel Detail { get; set; } } <ItemsControl ItemsSource="{Binding DetailViewModels}"> <ItemsControl> <ItemsPanelTemplate> <StackPanel /> </ItemsPanelTemplate> </ItemsControl> <ItemsControl.ItemTemplate> <DataTemplate> <views:DetailsView /> </DataTemplate> </ItemsControl.ItemTemplate> </ItemsControl> With this in mind I will now come to my questions. I read a lot of good things about MEF and also saw the dashboard sample of Glenn Block but this was not helping me enough. What I want to do is sidbar (like the windows sidebar). Sidebar = StackPanel ListItems = Gadget ButI want it MVVM style OK I have something like a contract IGadget I implemented an custom Export. [ExportGadget(GadgetType = GadgetTypes.News)] I have my NewsGadgetView.xaml (which implements IGadget) and imports the NewsGadgetViewModel and also makes itself available as ExportGadget. so far so good. With this I can create a set of gadgets. Then I have my SidbarView.xaml which imports a sidebarViewModel. and now I get lost... I thought of something like a GadgetFactory which uses PartCreator to create my Gadgets. but this would sit in my SidebarView.xaml But I want to have control over my Gadgets to add and remove them from my sidebar. So I thought about something like an ObserveableCollection... Which I bind to The GadgetHost is basicaly Grid which will dynamicaly load the Gadget.... So how would I create my sidebar containing different gadgets without knowing which Gadgets are available and have a ViewModel for the sidebar as well as for each gadget?... Thanks for any help....

    Read the article

  • Displaying a collection of controls in a specific way in WPF

    - by Alvaro
    I have a collection of controls "MyCollection" wich changes in the Runtime. And I have to follow some constraints for that, for example: If my parameter "MyCollection.Count = 4" the property "NumberOfcolumns" will have the value 2, in order to create new Lines, and show the controls Two per Two. This is how I'm displaying my collection : <ItemsControl ItemsSource="{Binding MyCollection}" BorderThickness="0" HorizontalContentAlignment="Center" VerticalContentAlignment="Center" > <ItemsControl.ItemsPanel> <ItemsPanelTemplate > <UniformGrid Columns="{Binding NumberOfColumns}" VerticalAlignment="Center" HorizontalAlignment="Center" Background="Transparent"/> </ItemsPanelTemplate> </ItemsControl.ItemsPanel> </ItemsControl> The problem is that my controls have different sizes, and as In UniformGrids, Cells are uniform... My design is not really pretty, because I have little controls shown in big Cells !! Can someone help me to solve this problem ? NB: Please give me a detailled solution if possible, not something like : "Use WrapPanel..."

    Read the article

  • Combobox binding with different types

    - by George Evjen
    Binding to comboboxes in Silverlight has been an adventure the past couple of days. In our framework at ArchitectNow we use LookupGroups and LookupValues. In our database we would have a LookupGroup of NBA Teams for example. The group would be called NBATeams, we get the LookupGroupID and then get the values from the LookupValues table. So we would end up with a list of all 30+ teams. Our lookup values entity has a display text(string), value(string), IsActive and some other fields. With our applications we load all this information into the system when the user is logging in or right after they login. So in cache we have a list of groups and values that we can get at whenever we want to. We get this information in our framework simply by creating an observable collection of type LookupValue. To get a list of these values into our property all we have to do is. var NBATeams = AppContext.Current.LookupSerivce.GetLookupValues(“NBATeams”); Our combobox then is bound like this. (We use telerik components in most if not all our projects) <telerik:RadComboBox ItemsSource="{Binding NBATeams}”></telerik:RadComboBox> This should give you a list in your combobox. We also set up another property in our ViewModel that is a just single object of NBATeams  - “SelectedNBATeam” Our selectedItem in our combobox would look like, we would set this to a two way binding since we are sending data back. SelectedItem={Binding SelectedNBATeam, mode=TwoWay}” This is all pretty straight forward and we use this pattern throughout all our applications. What do you do though when you have a combobox in a ItemsControl or ListBox? Here we have a list of NBA Teams that are a string that are being brought back from the database. We cant have the selected item be our LookupValue because the data is a string and its being bound in an ItemsControl. In the example above we would just have the combobox in a form. Here though we have it in a ItemsControl, where there is no selected item from the initial ItemsSource. In order to get the selected item to be displayed in the combobox you have to convert the LookupValue to a string. Then instead of using SelectedItem in the combobox use SelectedValue. To convert the LookupValue we do this. Create an observable collection of strings public ObservableCollection<string> NBATeams { get; set;} Then convert your lookups to strings var NBATeams = new ObservableCollection<string>(AppContext.Current.LookupService.GetLookupValues(“NBATeams”).Select(x => x.DisplayText)); This will give us a list of strings and our selected value should be bound to the NBATeams property in our ItemsSource in our ItemsControl. SelectedValue={Binding NBATeam, mode=TwoWay}”

    Read the article

  • How do I update ItemTemplate after scrambling ObservableCollection(Of ObservableCollection(Of object

    - by user342195
    I am learning vb.net, wpf and xaml with the help of sites like this one. The project I am currently working on is a 4 x 4 slide puzzle. I cannot get the buttons in the grid to scramble to start a new game when calling a new game event. Any help will be greatly appreciated. If no answer is can be provide, a good resource to research would help as well. Thank you for your time. XAML: <Window x:Class="SlidePuzzle" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Title="Slide Puzzle" Height="391" Width="300" Name="wdw_SlidePuzzle"> <Window.Resources> <DataTemplate x:Key="DataTemp_PuzzleButtons"> <Button Content="{Binding C}" Height="50" Width="50" Margin="2" Visibility="{Binding V}"/> </DataTemplate> <DataTemplate x:Key="DataTemplate_PuzzleBoard"> <ItemsControl ItemsSource="{Binding}" ItemTemplate="{DynamicResource DataTemp_PuzzleButtons}"> <ItemsControl.ItemsPanel> <ItemsPanelTemplate> <Canvas/> </ItemsPanelTemplate> </ItemsControl.ItemsPanel> <ItemsControl.ItemContainerStyle> <Style> <Setter Property="Canvas.Top" Value="{Binding Path=Y}" /> <Setter Property="Canvas.Left" Value="{Binding Path=X}" /> </Style> </ItemsControl.ItemContainerStyle> </ItemsControl> </DataTemplate> </Window.Resources> <DockPanel Name="dpanel_puzzle" LastChildFill="True"> <WrapPanel DockPanel.Dock="Bottom" Margin="5" HorizontalAlignment="Center"> <Button Name="bttnNewGame" Content="New Game" MinWidth="75" Margin="4" Click="NewGame_Click"></Button> <Button Name="bttnSolveGame" Content="Solve" MinWidth="75" Margin="4"></Button> <Button Name="bttnExitGame" Content="Exit" MinWidth="75" Margin="4" Click="ExitGame_Click"></Button> </WrapPanel> <WrapPanel DockPanel.Dock="Bottom" Margin="5" HorizontalAlignment="Center"> <Label>Score:</Label> <TextBox Name="tb_Name" Width="50"></TextBox> </WrapPanel> <StackPanel Name="SlidePuzzlePnl" HorizontalAlignment="Center" VerticalAlignment="Center" Height="206" Width="206" > <ItemsControl x:Name="lst" ItemTemplate="{DynamicResource DataTemplate_PuzzleBoard}"/> </StackPanel> </DockPanel> VB: Imports System.Collections.ObjectModel Class SlidePuzzle Dim puzzleColl As New ObservableCollection(Of ObservableCollection(Of SlidePuzzleBttn)) Dim puzzleArr(3, 3) As Integer Private Sub Window1_Loaded(ByVal sender As System.Object, ByVal e As System.Windows.RoutedEventArgs) Handles MyBase.Loaded For i As Integer = 0 To 3 puzzleColl.Add(New ObservableCollection(Of SlidePuzzleBttn)) For j As Integer = 0 To 3 puzzleArr(i, j) = (i * 4) + (j + 1) puzzleColl(i).Add(New SlidePuzzleBttn((i * 4) + (j + 1))) puzzleColl(i)(j).X = j * 52 puzzleColl(i)(j).Y = i * 52 Next Next lst.ItemsSource = puzzleColl End Sub Private Sub NewGame_Click(ByVal sender As System.Object, ByVal e As System.Windows.RoutedEventArgs) Dim rnd As New Random Dim ri, rj As Integer Dim temp As Integer For i As Integer = 0 To 3 For j As Integer = 0 To 3 ri = rnd.Next(0, 3) rj = rnd.Next(0, 3) temp = puzzleArr(ri, rj) puzzleArr(ri, rj) = puzzleArr(i, j) puzzleArr(i, j) = temp puzzleColl(i)(j).X = j * 52 puzzleColl(i)(j).Y = i * 52 puzzleColl(i)(j).C = puzzleArr(i, j) Next Next End Sub End Class Public Class SlidePuzzleBttn Inherits DependencyObject Private _c As Integer Private _x As Integer Private _y As Integer Private _v As String Public Shared ReadOnly ContentProperty As DependencyProperty = DependencyProperty.RegisterAttached("_c", GetType(String), GetType(SlidePuzzleBttn), New UIPropertyMetadata("")) Public Sub New() _c = 0 _x = 0 _y = 0 _v = SetV(_c) End Sub Public Sub New(ByVal cVal As Integer) _c = cVal _x = 0 _y = 0 _v = SetV(cVal) End Sub Public Property C() As Integer Get Return _c End Get Set(ByVal value As Integer) _c = value End Set End Property Public Property X() As Integer Get Return _x End Get Set(ByVal value As Integer) _x = value End Set End Property Public Property Y() As Integer Get Return _y End Get Set(ByVal value As Integer) _y = value End Set End Property Public Property V() As String Get Return _v End Get Set(ByVal value As String) _v = value End Set End Property Private Function SetV(ByRef cVal As Integer) As String If cVal = 16 Then Return "Hidden" Else Return "Visible" End If End Function End Class

    Read the article

  • WPF Navigation Page Breadcrumb

    - by Ryan
    I found code to use a breadcrumb instead of the navigation buttons for my pages. This code works perfect with setting a page as the startup. My problem is that I need to have a window with a frame control as the startup and this is causing the breadcrumb to not show at all. I seem to be missing something with my styling. The types used to be NavigationWindow but I changed them to Frame to try and get a working solution. <Style TargetType="Frame" x:Key="{x:Type Frame}"> <Setter Property="Template"> <Setter.Value> <ControlTemplate TargetType="Frame"> <Grid Background="Transparent"> <Grid.RowDefinitions> <RowDefinition Height="50"/> <RowDefinition Height="50"/> <RowDefinition Height="*"/> </Grid.RowDefinitions> <ItemsControl ItemsSource="{Binding RelativeSource={RelativeSource AncestorType={x:Type Frame}}, Path=BackStack}"> <!--Force the ItemsContol to use a wrap panel as Items host--> <ItemsControl.ItemsPanel> <ItemsPanelTemplate> <local:InverseWrapPanel KeyboardNavigation.TabNavigation="Cycle" KeyboardNavigation.DirectionalNavigation="Cycle"/> </ItemsPanelTemplate> </ItemsControl.ItemsPanel> <ItemsControl.ItemTemplate> <DataTemplate> <Button Command="NavigationCommands.NavigateJournal" CommandParameter="{Binding RelativeSource={RelativeSource Self}}" Content="{Binding Name}"> <Button.Template> <ControlTemplate TargetType="Button"> <WrapPanel> <TextBlock Name="text1" FontWeight="Bold" Text="{TemplateBinding Content}"/> <TextBlock Name="text2" FontWeight="Bold" Text=">>" Margin="2,0,0,0"/> </WrapPanel> <ControlTemplate.Triggers> <Trigger Property="IsMouseOver" Value="True"> <Setter TargetName="text1" Property="Foreground" Value="Blue"/> <Setter TargetName="text2" Property="Foreground" Value="Blue"/> </Trigger> </ControlTemplate.Triggers> </ControlTemplate> </Button.Template> </Button> </DataTemplate> </ItemsControl.ItemTemplate> </ItemsControl> <AdornerDecorator Grid.Row="2"> <ContentPresenter Name="PART_NavWinCP" ClipToBounds="true"/> </AdornerDecorator> </Grid> </ControlTemplate> </Setter.Value> </Setter> </Style>

    Read the article

  • Why do I get a NullReferenceException when using a style on a ContentPresenter?

    - by Robert Rossney
    I've created this template, which uses a style applied to the ContentPresenter so that I can bind the data object's Column property to Grid.Column, allowing the items to determine for themselves which column of the Grid they go into: <DataTemplate DataType="{x:Type local:MyObject}"> <ItemsControl ItemsSource="{Binding Items}"> <ItemsControl.Resources> <Style TargetType="{x:Type ContentPresenter}"> <Setter Property="Grid.Column" Value="{Binding Column}" /> </Style> </ItemsControl.Resources> <ItemsControl.ItemsPanel> <ItemsPanelTemplate> <Grid> <Grid.ColumnDefinitions> <ColumnDefinition Width="*" /> <ColumnDefinition Width="*" /> <ColumnDefinition Width="*" /> </Grid.ColumnDefinitions> </Grid> </ItemsPanelTemplate> </ItemsControl.ItemsPanel> </ItemsControl> </DataTemplate> When I run the program, I get a NullReferenceException. The beginning of the hilariously long stack trace: at System.Windows.StyleHelper.ApplyAutoAliasRules(OptimizedTemplateContent optimizedTemplateContent, HybridDictionary childIndexFromChildID, FrameworkTemplate frameworkTemplate, FrugalStructList`1& childRecordFromChildIndex, FrugalStructList`1& triggerSourceRecordFromChildIndex, FrugalStructList`1& resourceDependents, HybridDictionary& dataTriggerRecordFromBinding, Boolean& hasInstanceValues) at System.Windows.StyleHelper.ProcessTemplateContent(FrameworkTemplate frameworkTemplate, FrugalStructList`1& childRecordFromChildIndex, FrugalStructList`1& triggerSourceRecordFromChildIndex, FrugalStructList`1& resourceDependents, ItemStructList`1& eventDependents, HybridDictionary& dataTriggerRecordFromBinding, HybridDictionary childIndexFromChildID, Boolean& hasInstanceValues) at System.Windows.StyleHelper.SealTemplate(FrameworkTemplate frameworkTemplate, Boolean& isSealed, FrameworkElementFactory templateRoot, TriggerCollection triggers, ResourceDictionary resources, HybridDictionary childIndexFromChildID, FrugalStructList`1& childRecordFromChildIndex, FrugalStructList`1& triggerSourceRecordFromChildIndex, FrugalStructList`1& containerDependents, FrugalStructList`1& resourceDependents, ItemStructList`1& eventDependents, HybridDictionary& triggerActions, HybridDictionary& dataTriggerRecordFromBinding, Boolean& hasInstanceValues, EventHandlersStore& eventHandlersStore) at System.Windows.FrameworkTemplate.Seal() at System.Windows.StyleHelper.UpdateTemplateCache(FrameworkElement fe, FrameworkTemplate oldTemplate, FrameworkTemplate newTemplate, DependencyProperty templateProperty) at System.Windows.Controls.ContentPresenter.OnTemplateChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) at System.Windows.DependencyObject.OnPropertyChanged(DependencyPropertyChangedEventArgs e) at System.Windows.FrameworkElement.OnPropertyChanged(DependencyPropertyChangedEventArgs e) at System.Windows.DependencyObject.NotifyPropertyChange(DependencyPropertyChangedEventArgs args) ...etc. It's not the binding. I still get the error if I explicitly set the value in the style's setter to 0, say. And the error vanishes if I remove the style, though then all of the items end up in column 0. What's going on here? And how do I debug a problem like this?

    Read the article

  • WPF - expander Collapsed event being triggered by child controls with validation

    - by Shaboboo
    I have an expander that contains an ItemsControl. The items in the itemsControl are templated, some have textboxes in them, others have checkboxes. Both have bindings that cause validation. The styling and validation is working as expected. The problem is when I first expand the expander and cause a change to either control, the expander collapses again, this is not what I want. If I repeat this a second time this does not happen. I'm not sure what is triggering this strange behaviour. I've tried setting the focus to the itemsControl when the expander expands with no luck. What is differnt the second time it's expanded? Could it be the validation? Any Ideas? XAML: <Expander Header="{Binding SubSectionName}" Padding="0" > <ItemsControl ItemsSource="{Binding ConfigSubSectionSettings}" ItemTemplateSelector="{StaticResource Settings_Selector}" /> </Expander> <!-- Templates selected by the ItemTemplateSelector --> <DataTemplate x:Key="subSection_Bool"> <StackPanel Orientation="Horizontal"> <TextBlock x:Name="lbl" Text="{Binding SubSectionName}" > <CheckBox x:Name="chk" IsChecked="{Binding BoolValue, ValidatesOnDataErrors=True}" VerticalAlignment="Center" Margin="2" > </StackPanel > </DataTemplate> <DataTemplate x:Key="subSection_Text"> <StackPanel Orientation="Horizontal"> <TextBlock x:Name="lbl" Text="{Binding SubSectionName}" /> <TextBox x:Name="txt" VerticalAlignment="Center" Text="{Binding StringValue, ValidatesOnDataErrors=True}" /> </StackPanel> </DataTemplate>

    Read the article

  • Master Detail same View binding controls

    - by pipelinecache
    Hi everyone, say I have a List View with ItemControls. And a Details part that shows the selected Item from List View. Both are in the same xaml page. I tried everything to accomplish it, but what do I miss? <!-- // List --> <ItemsControl ItemsSource="{Binding Path=Model, ElementName=SomeListViewControl, Mode=Default}" SnapsToDevicePixels="True" Focusable="False" IsTabStop="False"> <ItemsControl.ItemTemplate> <DataTemplate> <SomeListView:SomeListItemControl x:Name=listItem/> </DataTemplate> </ItemsControl.ItemTemplate> </ItemsControl> <!-- // Details --> <Label Content="Begindatum" FontSize="16" VerticalAlignment="Center" Grid.Row="1" Margin="2,0,0,0"/> <TextBox x:Name="Begindatum" Grid.Column="1" Grid.Row="1" Text="{Binding Path=BeginDate, ElementName=listItem,Converter={StaticResource DateTimeConverter}, ConverterParameter=dd-MM-yyyy}" IsEnabled="False" Style="{DynamicResource TextBoxStyle}" MaxLength="30"/> public event EventHandler<DataEventArgs<SomeEntity>> OnOpenSomething; public ObservableCollection<SomeEntity> Model { get { return (ObservableCollection<SomeEntity>)GetValue(ModelProperty); } set { Model.CollectionChanged -= new NotifyCollectionChangedEventHandler(Model_CollectionChanged); SetValue(ModelProperty, value); Model.CollectionChanged += new NotifyCollectionChangedEventHandler(Model_CollectionChanged); UpdateVisualState(); } } public static readonly DependencyProperty ModelProperty = DependencyProperty.Register("Model", typeof(ObservableCollection<SomeEntity>), typeof(SomeListView), new UIPropertyMetadata(new ObservableCollection<SomeEntity>(), new PropertyChangedCallback(ChangedModel))); private static void ChangedModel(DependencyObject source, DependencyPropertyChangedEventArgs e) { SomeListView someListView = source as SomeListView; if (someListView.Model == null) { return; } CollectionView cv = (CollectionView)CollectionViewSource.GetDefaultView(someListView.Model); } private void Model_CollectionChanged(object sender, NotifyCollectionChangedEventArgs e) { if (Model == null) { return; } }

    Read the article

  • Populate two column grid with databinding?

    - by Richard
    How do i populate a two column grid with objects from my observable collection? I've tried to achieve this effect by using the tookits wrap panel but the items just stack. <toolkit:WrapPanel Margin="5,0,0,0" Width="400"> <ItemsControl ItemsSource="{Binding Trips}"> <ItemsControl.ItemTemplate> <DataTemplate> <StackPanel Height="236" Width="182"> <Button Style="{StaticResource VasttrafikButtonTrip}"> <StackPanel Width="152" Height="140"> <TextBlock Text="{Binding FromName}" /> <TextBlock FontFamily="Segoe WP Semibold" Text="till" /> <TextBlock Text="{Binding ToName}" /> </StackPanel> </Button> <TextBlock HorizontalAlignment="Left" Width="160" FontSize="16" FontWeight="ExtraBlack" Text="{Binding TravelTimeText}" /> <TextBlock HorizontalAlignment="Left" Width="160" Margin="0,-6,0,0" FontSize="16" Text="{Binding TransferCountText}" /> </StackPanel> </DataTemplate> </ItemsControl.ItemTemplate> </ItemsControl> </toolkit:WrapPanel>

    Read the article

  • How can I incorporate a data bound list of MenuItems to another MenuItem in WPF?

    - by Julien Poulin
    I have a 'File' MenuItem were I would like to display a list of recently opened files. Here is the xaml I have now: <MenuItem Header="File}"> <MenuItem Header="Preferences..." Command="{Binding ShowOptionsViewCommand}" /> <Separator /> <ItemsControl ItemsSource="{Binding RecentFiles}"> <ItemsControl.ItemTemplate> <DataTemplate> <MenuItem Header="{Binding DisplayPath}" CommandParameter="{Binding}" Command="{Binding Path=DataContext.OpenRecentFileCommand, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type Window}}}"> </MenuItem> </DataTemplate> </ItemsControl.ItemTemplate> </ItemsControl> <Separator /> <MenuItem Header="Exit" Command="{Binding CloseCommand}" /> </MenuItem> However, when I use this code, there is a weird offset around the MenuItems and it looks like there is a container around them. How can I get rid of that? Here is a screenshot of what it looks like:

    Read the article

  • Prevent WPF control from expanding beyond viewable area

    - by Dan dot net
    I have an Items Control in my user control with a scroll viewer around it for when it gets too big (Too big being content is larger than the viewable area of the user control). The problem is that the grid that it is all in just keeps expanding so that the scroll viewer never kicks in (unless I specify an exact height for the grid). See code below and thanks in advance. <Grid HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Height="300px"> <Grid.RowDefinitions> <RowDefinition Height="*" /> </Grid.RowDefinitions> <GroupBox FontWeight="Bold" Header="Tables" Padding="2"> <ScrollViewer> <ItemsControl FontWeight="Normal" ItemsSource="{Binding Path=AvailableTables}"> <ItemsControl.ItemTemplate> <DataTemplate> <CheckBox Content="{Binding Path=DisplayName}" IsChecked="{Binding Path=IsSelected}" Margin="2,3.5" /> </DataTemplate> </ItemsControl.ItemTemplate> </ItemsControl> </ScrollViewer> </GroupBox> </Grid> I would like to not specify the height.

    Read the article

< Previous Page | 1 2 3 4 5 6 7  | Next Page >