Search Results

Search found 160 results on 7 pages for 'tabcontrol'.

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

  • WPF Grid Row / Column Sizing in Proportion to DesiredSize?

    - by sinibar
    I have two user controls arranged vertically in a grid, both of which can expand to be taller than the grid can accommodate. I've put them in each in a scrollviewer which functionally works. What I want though is to give them them space in proportion to the amount that they want at run time. So if there's 500 height available, the upper control wants 400 and the lower 600, the upper control would get 200 and the bottom 300. I have no idea at design time how much space each will want in proportion to the other, so using 1*, 2* etc. for row height won't work for me. I can hand-code run-time proportional sizing, but am I missing a simple trick in XAML that would get me what I want? Context is as follows (trimmed for brevity)... <Grid> <TabControl> <TabItem> <Grid> <Grid> <Grid.RowDefinitions> <RowDefinition Height="Auto"/> <RowDefinition Height="*"/> <RowDefinition Height="*"/> </Grid.RowDefinitions> <GroupBox Grid.Row="0" Header="Title Area" /> <ScrollViewer Grid.Row="1" VerticalScrollBarVisibility="Auto"> <UserControl /> </ScrollViewer> <ScrollViewer Grid.Row="2" VerticalScrollBarVisibility="Auto"> <UserControl /> </ScrollViewer> </Grid> </Grid> </TabItem> </TabControl> </Grid>

    Read the article

  • New TabItem Content ActualHeight crashes Xaml Window

    - by Jack Navarro
    I am able to create new TabItems with Content dynamically to a new window by streaming the Xaml with XamlReader: NewWindow newWindow = new NewWindow(); newWindow.Show(); TabControl myTabCntrol = newWindow.FindName("GBtabControl") as TabControl; StringReader stringReader = new StringReader(XamlGrid); XmlReader xmlReader = XmlReader.Create(stringReader); TabItem myTabItem = new TabItem(); myTabItem.Header = qDealName; myTabItem.Content = (UIElement)XamlReader.Load(xmlReader); myTabCntrol.Items.Add(myTabItem); This works fine. It displays a new grid wrapped in a scrollviewer. The problem is access the TabItem content from the newWindow. TabItem ti = GBtabControl.SelectedItem as TabItem; string scrollvwnm = "scrollViewer" + ti.Header.ToString(); MessageBox.Show(ti.ActualHeight.ToString()); // returns 21.5 ScrollViewer scrlvwr = this.FindName(scrollvwnm) as ScrollViewer; MessageBox.Show(scrollvwnm); // Displays name double checked for accuracy MessageBox.Show(scrlvwr.ActualHeight.ToString()); //Crashes ScrollViewer scrlvwr = ti.FindName(scrollvwnm) as ScrollViewer; MessageBox.Show(scrollvwnm); // Displays name double checked for accuracy MessageBox.Show(scrlvwr.ActualHeight.ToString()); //Also Crashes Is there a method to refresh UI in XAML so the new window is able to access the newly loaded tab item content? Thanks

    Read the article

  • How to control the order of module initialization in Prism

    - by Robert Taylor
    I'm using Prism V2 with a DirectoryModuleCatalog and I need the modules to be initialized in a certain order. The desired order is specified with an attribute on each IModule implementation. This is so that as each module is initialized, they add their View into a TabControl region and the order of the tabs needs to be deterministic and controlled by the module author. The order does not imply a dependency, but rather just an order that they should be initialized in. In other words: modules A, B, and C may have priorities of 1, 2, and 3 respectively. B does not have a dependency on A - it just needs to get loaded into the TabControl region after A. So that we have a deterministic and controllable order of the tabs. Also, B might not exist at runtime; so they would load as A, C because the priority should determine the order (1, 3). If i used the ModuleDependency, then module "C" will not be able to load w/o all of it's dependencies. I can manage the logic of how to sort the modules, but i can't figure out where to put said logic.

    Read the article

  • WPF, notify a child in the element tree about an event in a parent

    - by jester
    I am developing a WPF app and I want an event in a parent to be notified to several of its children in the element tree, so that each of them can take an action accordingly. I know that a custom RoutedEvent can be used to signal in the other direction from a child to one of its ancestors by bubbling the event upwards, so that any of the ancestor elements can handle the event. What I want is the children to be notified about an event in the parent and they handle them appropriately. What is the best strategy to achieve this? EDIT: Clarifying the comments : Say I have a parent UserControl. It has a TabControl and its contents are several nested child UserControls. Now consider a scenario where I want the TabControl.SelectionChanged() event to cause some changes in each of the child UserControl. How to achieve this? (The contents of each tab is a UserControl which themselves may contain another few levels of children UserControls. I want the UserControl in the bottom level to know about the SelectionChanged() event and respond accordingly).

    Read the article

  • Sizing issues while adding a .Net UserControl to a TabPage

    - by TJ_Fischer
    I have a complex Windows Forms GUI program that has a lot of automated control generation and manipulation. One thing that I need to be able to do is add a custom UserControl to a newly instatiated TabPage. However, when my code does this I get automatic resizing events that cause the formatting to get ugly. Without detailing all of the different Containers that could possibly be involved, the basic issue is this: At a certain point in the code I create a new tab page: TabPage tempTabPage = new TabPage("A New Tab Page"); Then I set it to a certain size that I want it to maintain: tempTabPage.Width = 1008; tempTabPage.Height = 621; Then I add it to a TabControl: tabControl.TabPages.Add(tempTabPage); Then I create a user control that I want to appear in the newly added TabPage: CustomView customView = new CustomView("A new custom control"); Here is where the problem comes in. At this point both the tempTabPage and the customView are the same size with no padding or margin and they are the size I want them to be. I now try to add this new custom UserControl to the tab page like this: tempTabPage.Controls.Add(customView); When making this call the customView and it's children controls get resized to be larger and so parts of the customView are hidden. Can anyone give me any direction on what to look for or what could be causing this kind of issue? Thanks ahead of time.

    Read the article

  • Bound Command not firing on another viewModel? What Am I doing wrong?

    - by devnet247
    Hi I cannot seem to bind a command to a button.I have a treeview on the left showing Country City etc.. And I tabcontrol on the right. do I This uses 4 viewModels rootviewModel-ContinentViewModel-CountryViewModel-CityViewModel What I am building is based on http://www.codeproject.com/KB/WPF/TreeViewWithViewModel.aspx Now on one of the tabs I have a Toolbar with a button "TestButton" that I have mapped in zaml. This does not fire! The reason is not firing is because I m binding the RootViewModel but the command that is bound in zaml is in the cityViewModel. How Do I pass the datacontext from one view to the other? or how do I make the button fire. I need the command to be in the cityViewModel. Any Suggestions on how I bind it? View "WorldExplorerView" where I bind the main DataContext public partial class WorldExplorerView { public WorldExplorerView() { InitializeComponent(); var continents = Database.GetContinents(); var rootViewModel = new RootViewModel(continents); DataContext = rootViewModel; } } CityViewModel public class CityViewModel : TreeViewItemViewModel { private City _city; private RelayCommand _testCommand; public CityViewModel(City city, CountryViewModel countryViewModel):base(countryViewModel,false) { _city = city; } Properties etc...... public ICommand TestCommand { get { if(_testCommand==null) { _testCommand = new RelayCommand(param => GetTestCommand(), param => CanCallTestCommand); ; } return _testCommand; } } protected bool CanCallTestCommand { get { return true; } } private static void GetTestCommand() { MessageBox.Show("It works"); } } ZAML <DockPanel> <DockPanel LastChildFill="True"> <Label DockPanel.Dock="top" Content="Title " HorizontalAlignment="Center"></Label> <StatusBar DockPanel.Dock="Bottom"> <StatusBarItem Content="Status Bar" ></StatusBarItem> </StatusBar> <Grid DockPanel.Dock="Top"> <Grid.ColumnDefinitions> <ColumnDefinition/> <ColumnDefinition Width="Auto"/> <ColumnDefinition Width="2*"/> </Grid.ColumnDefinitions> <TreeView Name="tree" ItemsSource="{Binding Continents}"> <TreeView.ItemContainerStyle> <Style TargetType="{x:Type TreeViewItem}"> <Setter Property="IsExpanded" Value="{Binding IsExpanded,Mode=TwoWay}"/> <Setter Property="IsSelected" Value="{Binding IsSelected,Mode=TwoWay}"/> <Setter Property="FontWeight" Value="Normal"/> <Style.Triggers> <Trigger Property="IsSelected" Value="True"> <Setter Property="FontWeight" Value="Bold"></Setter> </Trigger> </Style.Triggers> </Style> </TreeView.ItemContainerStyle> <TreeView.Resources> <HierarchicalDataTemplate DataType="{x:Type ViewModels:ContinentViewModel}" ItemsSource="{Binding Children}"> <StackPanel Orientation="Horizontal"> <Image Width="16" Height="16" Margin="3,0" Source="Images\Continent.png"/> <TextBlock Text="{Binding ContinentName}"/> </StackPanel> </HierarchicalDataTemplate> <HierarchicalDataTemplate DataType="{x:Type ViewModels:CountryViewModel}" ItemsSource="{Binding Children}"> <StackPanel Orientation="Horizontal"> <Image Width="16" Height="16" Margin="3,0" Source="Images\Country.png"/> <TextBlock Text="{Binding CountryName}"/> </StackPanel> </HierarchicalDataTemplate> <DataTemplate DataType="{x:Type ViewModels:CityViewModel}" > <StackPanel Orientation="Horizontal"> <Image Width="16" Height="16" Margin="3,0" Source="Images\City.png"/> <TextBlock Text="{Binding CityName}"/> </StackPanel> </DataTemplate> </TreeView.Resources> </TreeView> <GridSplitter Grid.Row="0" Grid.Column="1" Background="LightGray" Width="5" HorizontalAlignment="Stretch" VerticalAlignment="Stretch"/> <Grid Grid.Column="2" Margin="5" > <TabControl> <TabItem Header="Demo"> <DockPanel LastChildFill="True"> <ToolBar DockPanel.Dock="Top"> <!-- DOES NOT WORK--> <Button Name="btnTest" Command="{Binding TestCommand}" Content="Press me see if works"></Button> </ToolBar> <TextBox></TextBox> </DockPanel> </TabItem> <TabItem Header="Details" DataContext="{Binding Path=SelectedItem.City, ElementName=tree, Mode=OneWay}"> <StackPanel > <TextBlock VerticalAlignment="Center" FontSize="12" Text="{Binding CityName}"/> <TextBlock VerticalAlignment="Center" FontSize="12" Text="{Binding Area}"/> <TextBlock VerticalAlignment="Center" FontSize="12" Text="{Binding Population}"/> <TextBlock VerticalAlignment="Center" FontSize="12" Text="{Binding CityDetailsInfo.ClubsCount}"/> <TextBlock VerticalAlignment="Center" FontSize="12" Text="{Binding CityDetailsInfo.PubsCount}"/> </StackPanel> </TabItem> </TabControl> </Grid> </Grid> </DockPanel> </DockPanel>

    Read the article

  • treeview binding wpf cannot bind nested property in a class

    - by devnet247
    Hi all New to wpf and therefore struggling a bit. I am putting together a quick demo before we go for the full implementation I have a treeview on the left with Continent Country City structure when a user select the city it should populate some textboxes in a tabcontrol on the right hand side I made it sort of work but cannot make it work with composite objects. In a nutshell can you spot what is wrong with my zaml or code. Why is not binding to a my CityDetails.ClubsCount or CityDetails.PubsCount? What I am building is based on http://www.codeproject.com/KB/WPF/TreeViewWithViewModel.aspx Thanks a lot for any suggestions or reply DataModel public class City { public City(string cityName) { CityName = cityName; } public string CityName { get; set; } public string Population { get; set; } public string Area { get; set; } public CityDetails CityDetailsInfo { get; set; } } public class CityDetails { public CityDetails(int pubsCount,int clubsCount) { PubsCount = pubsCount; ClubsCount = clubsCount; } public int ClubsCount { get; set; } public int PubsCount { get; set; } } ViewModel public class CityViewModel : TreeViewItemViewModel { private City _city; private RelayCommand _testCommand; public CityViewModel(City city, CountryViewModel countryViewModel):base(countryViewModel,false) { _city = city; } public string CityName { get { return _city.CityName; } } public string Area { get { return _city.Area; } } public string Population { get { return _city.Population; } } public City City { get { return _city; } set { _city = value; } } public CityDetails CityDetailsInfo { get { return _city.CityDetailsInfo; } set { _city.CityDetailsInfo = value; } } } XAML <DockPanel> <DockPanel LastChildFill="True"> <Label DockPanel.Dock="top" Content="Title " HorizontalAlignment="Center"></Label> <StatusBar DockPanel.Dock="Bottom"> <StatusBarItem Content="Status Bar" ></StatusBarItem> </StatusBar> <Grid DockPanel.Dock="Top"> <Grid.ColumnDefinitions> <ColumnDefinition/> <ColumnDefinition Width="Auto"/> <ColumnDefinition Width="2*"/> </Grid.ColumnDefinitions> <TreeView Name="tree" ItemsSource="{Binding Continents}"> <TreeView.ItemContainerStyle> <Style TargetType="{x:Type TreeViewItem}"> <Setter Property="IsExpanded" Value="{Binding IsExpanded,Mode=TwoWay}"/> <Setter Property="IsSelected" Value="{Binding IsSelected,Mode=TwoWay}"/> <Setter Property="FontWeight" Value="Normal"/> <Style.Triggers> <Trigger Property="IsSelected" Value="True"> <Setter Property="FontWeight" Value="Bold"></Setter> </Trigger> </Style.Triggers> </Style> </TreeView.ItemContainerStyle> <TreeView.Resources> <HierarchicalDataTemplate DataType="{x:Type ViewModels:ContinentViewModel}" ItemsSource="{Binding Children}"> <StackPanel Orientation="Horizontal"> <Image Width="16" Height="16" Margin="3,0" Source="Images\Continent.png"/> <TextBlock Text="{Binding ContinentName}"/> </StackPanel> </HierarchicalDataTemplate> <HierarchicalDataTemplate DataType="{x:Type ViewModels:CountryViewModel}" ItemsSource="{Binding Children}"> <StackPanel Orientation="Horizontal"> <Image Width="16" Height="16" Margin="3,0" Source="Images\Country.png"/> <TextBlock Text="{Binding CountryName}"/> </StackPanel> </HierarchicalDataTemplate> <DataTemplate DataType="{x:Type ViewModels:CityViewModel}" > <StackPanel Orientation="Horizontal"> <Image Width="16" Height="16" Margin="3,0" Source="Images\City.png"/> <TextBlock Text="{Binding CityName}"/> </StackPanel> </DataTemplate> </TreeView.Resources> </TreeView> <GridSplitter Grid.Row="0" Grid.Column="1" Background="LightGray" Width="5" HorizontalAlignment="Stretch" VerticalAlignment="Stretch"/> <Grid Grid.Column="2" Margin="5" > <TabControl> <TabItem Header="Details" DataContext="{Binding Path=SelectedItem.City, ElementName=tree, Mode=OneWay}"> <StackPanel > <TextBlock VerticalAlignment="Center" FontSize="12" Text="{Binding CityName}"/> <TextBlock VerticalAlignment="Center" FontSize="12" Text="{Binding Area}"/> <TextBlock VerticalAlignment="Center" FontSize="12" Text="{Binding Population}"/> <!-- DONT WORK WHY--> <TextBlock VerticalAlignment="Center" FontSize="12" Text="{Binding SelectedItem.CityDetailsInfo.ClubsCount}"/> <TextBlock VerticalAlignment="Center" FontSize="12" Text="{Binding SelectedItem.CityDetailsInfo.PubsCount}"/> </StackPanel> </TabItem> </TabControl> </Grid> </Grid> </DockPanel> </DockPanel>

    Read the article

  • how to use multiple tab controls, and to be able to call a selected tab control with buttons.

    - by mojotaker
    Please I am trying to assign each button on the left its own Tab control. That is for example, when the Intake form button is pushed, it will have its own set of tabs (its own tabcontrols) am i supposed to place multiple tab controls on the artboard, or is there a way to programatically change the names of the tabs, and there contents, when a button is pushed on the left ? thank you in advance. and here is a link hxxp://img709.imageshack.us/img709/554/tabcontrol.gif here is the code so far <Window 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" x:Class="service.MainWindow" x:Name="Window" Title="MainWindow" Width="687" Height="480" mc:Ignorable="d"> <Window.Resources> <Storyboard x:Key="OnLoaded1"/> </Window.Resources> <Window.Triggers> <EventTrigger RoutedEvent="FrameworkElement.Loaded"> <BeginStoryboard Storyboard="{StaticResource OnLoaded1}"/> </EventTrigger> </Window.Triggers> <Grid x:Name="LayoutRoot" Margin="0,0,-16,1"> <Grid.ColumnDefinitions> <ColumnDefinition Width="0*"/> <ColumnDefinition/> </Grid.ColumnDefinitions> <DockPanel Margin="8,8,0,7" LastChildFill="False" Grid.Column="1" HorizontalAlignment="Left" Width="660"> <Menu VerticalAlignment="Top" Width="657" Height="32"> <MenuItem x:Name="file" Header="File"/> <MenuItem x:Name="edit" Header="Edit"> <MenuItem Width="100" Height="100" Header="MenuItem"/> </MenuItem> <MenuItem x:Name="view" Header="View"/> <MenuItem x:Name="preferences" Header="Preferences"/> <MenuItem x:Name="help" Header="Help"/> </Menu> </DockPanel> <TabControl x:Name="tabwin" Margin="137.224,46,19,7" Grid.Column="1"> <TabItem x:Name="intakeformsub" Header="Elegibility Form"> <Grid HorizontalAlignment="Left" Width="490"/> </TabItem> <TabItem Header="TabItem"> <Grid/> </TabItem> <TabItem Header="TabItem"> <Grid/> </TabItem> <TabItem Header="TabItem"> <Grid> <Grid.ColumnDefinitions> <ColumnDefinition Width="0.567*"/> <ColumnDefinition Width="0.433*"/> </Grid.ColumnDefinitions> </Grid> </TabItem> <TabItem Header="TabItem"> <Grid/> </TabItem> <TabItem Header="TabItem"> <Grid> <Grid.ColumnDefinitions> <ColumnDefinition Width="0.735*"/> <ColumnDefinition Width="0.265*"/> </Grid.ColumnDefinitions> </Grid> </TabItem> <TabItem Header="TabItem"> <Grid/> </TabItem> <TabItem Header="TabItem"> <Grid/> </TabItem> </TabControl> <Grid x:Name="___buttontab" Margin="11.205,61,0,0" Grid.Column="1" HorizontalAlignment="Left" Width="122.019" VerticalAlignment="Top" Height="276"> <Button VerticalAlignment="Top" Height="36" Content="Button"/> <Button Margin="0,40,0,0" Content="Oasis Assessments" VerticalAlignment="Top" Height="36"/> <Button Margin="0,80,0,0" VerticalAlignment="Top" Height="36" Content="Plan of Care"/> <Button Margin="0,120,0,0" VerticalAlignment="Top" Height="36" Content="Medication Profile" RenderTransformOrigin="0.421,5.556"/> <Button Margin="0,0,0,80" VerticalAlignment="Bottom" Height="36" Content="Clinical Notes"/> <Button Margin="0,0,0,40" VerticalAlignment="Bottom" Height="36" Content="Infection Control"/> <Button x:Name="intakeformbtn" VerticalAlignment="Top" Height="36" Content="Intake Form" Click="intakeform"> <Button.BindingGroup> <BindingGroup/> </Button.BindingGroup> </Button> <Button VerticalAlignment="Bottom" Height="36" Content="Discharge Summary"/> </Grid> <ProgressBar HorizontalAlignment="Left" Margin="8,0,0,7" VerticalAlignment="Bottom" Width="104.795" Height="19" Grid.Column="1"/> </Grid> </Window>

    Read the article

  • Databinding to ObservableCollection in a different UserControl?

    - by Dave
    Question re-written on 2010-03-24 I have two UserControls, where one is a dialog that has a TabControl, and the other is one that appears within said TabControl. I'll just call them CandyDialog and CandyNameViewer for simplicity's sake. There's also a data management class called Tracker that manages information storage, which for all intents and purposes just exposes a public property that is an ObservableCollection. I display the CandyNameViewer in CandyDialog via code behind, like this: private void CandyDialog_Loaded( object sender, RoutedEventArgs e) { _candyviewer = new CandyViewer(); _candyviewer.DataContext = _tracker; candy_tab.Content = _candyviewer; } The CandyViewer's XAML looks like this (edited for kaxaml): <Page xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"> <Page.Resources> <DataTemplate x:Key="CandyItemTemplate"> <Grid> <Grid.ColumnDefinitions> <ColumnDefinition Width="120"></ColumnDefinition> <ColumnDefinition Width="150"></ColumnDefinition> </Grid.ColumnDefinitions> <TextBox Grid.Column="0" Text="{Binding CandyName}" Margin="3"></TextBox> <!-- just binding to DataContext ends up using InventoryItem as parent, so we need to get to the UserControl --> <ComboBox Grid.Column="1" SelectedItem="{Binding SelectedCandy, Mode=TwoWay}" ItemsSource="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type UserControl}}, Path=DataContext.CandyNames}" Margin="3"></ComboBox> </Grid> </DataTemplate> </Page.Resources> <Grid> <ListBox DockPanel.Dock="Top" ItemsSource="{Binding CandyBoxContents, Mode=TwoWay}" ItemTemplate="{StaticResource CandyItemTemplate}" /> </Grid> </Page> Now everything works fine when the controls are loaded. As long as CandyNames is populated first, and then the consumer UserControl is displayed, all of the names are there. I obviously don't get any errors in the Output Window or anything like that. The issue I have is that when the ObservableCollection is modified from the model, those changes are not reflected in the consumer UserControl! I've never had this problem before; all of my previous uses of ObservableCollection updated fine, although in those cases I wasn't databinding across assemblies. Although I am currently only adding and removing candy names to/from the ObservableCollection, at a later date I will likely also allow renaming from the model side. Is there something I did wrong? Is there a good way to actually debug this? Reed Copsey indicates here that inter-UserControl databinding is possible. Unfortunately, my favorite Bea Stollnitz article on WPF databinding debugging doesn't suggest anything that I could use for this particular problem.

    Read the article

  • Dynamically set method for tabPage

    - by phenevo
    Hi, I dynamically add TabPage to my TabControl How to set method Select() for this tabpage TabPage tpTags = new TabPage(); tabControl1.TabPages.Add(tpTags); ...setting properties... tpTags.Select() =tpTags.BindData(); <= how do it ?

    Read the article

  • Re-using Buttons in WPF

    - by Alex Marshall
    I have a bunch of different objects that are commonly edited in the same TabControl using different DataTemplates, but I want each DataTemplate to have a common look and feel with Ok and Cancel buttons at the bottom right of each tab that will close the tab or save the content and then close the currently selected tab. What's the best way to place buttons on each tab ? Is there a way to do it without copying and pasting the buttons and stack panel across all of my data templates ?

    Read the article

  • WinAPI magic and MONO runtime

    - by Luca
    I'm trying to get the same result of a .NET application (see the link Hide TabControl buttons to manage stacked Panel controls for details), but using the MONO runtime instead of the MS .NET runtime. Pratically, when the custom control is executed using the MONO runtime, the underlying message is not sent to the control, causing the tab pages to be shown... Is there a portable solution which is elegant as the linked one? If it is not possible, what are possible workarounds (apart from removing/adding tabs at runtime)?

    Read the article

  • WPF Custom Control - Designer looks fine, but I get a runtime issue...

    - by myermian
    MainWindow.xaml <Window x:Class="MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:my="clr-namespace:MyStuff;assembly=MyStuff" Title="MainWindow" Height="350" Width="525"> <Grid> <TabControl Margin="5"> <TabItem Header="Start Page" /> <my:XTabItem Header="Tab 1" Image="Resources/icon1.png" /> </TabControl> </Grid> </Window> Generic.xaml <ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:local="clr-namespace:MyStuff" > <!-- XTabItem --> <Style TargetType="{x:Type local:XTabItem}"> <Setter Property="Template"> <Setter.Value> <ControlTemplate TargetType="{x:Type local:XTabItem}"> <Border Background="{TemplateBinding Background}" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}"> <StackPanel Orientation="Horizontal"> <Image Source="{Binding Path=Image, RelativeSource={RelativeSource TemplatedParent}}" Stretch="UniformToFill" MaxHeight="24" /> <TextBlock Text="{TemplateBinding Header}" /> <Button Content="X" /> </StackPanel> </Border> </ControlTemplate> </Setter.Value> </Setter> </Style> </ResourceDictionary> XTabItem.cs using System; using System.ComponentModel; using System.Windows; using System.Windows.Controls; using System.Windows.Media; namespace MyStuff { public class XTabItem : TabItem { #region Dependency Properties public static readonly DependencyProperty ImageProperty; #endregion #region Constructors / Initializer static XTabItem() { //Initialize the control as "lookless". DefaultStyleKeyProperty.OverrideMetadata(typeof(XTabItem), new FrameworkPropertyMetadata(typeof(XTabItem))); //Setup the dependency properties. ImageProperty = DependencyProperty.Register("Image", typeof(ImageSource), typeof(XTabItem), new UIPropertyMetadata(null)); } #endregion #region Custom Control Properties (Image) /// <summary> /// The image (icon) displayed by inside the tab header. /// </summary> /// <remarks>The image is specified in XAML as an absolute or relative path.</remarks> [Description("The image displayed by the button"), Category("Optional Properties")] public ImageSource Image { get { return (ImageSource)GetValue(ImageProperty); } set { SetValue(ImageProperty, value); } } #endregion } } Exception at line #9 () : XamlParseException : 'Provide value on 'System.Windows.Baml2006.TypeConverterMarkupExtension' threw an exception.' Line number '9' and line position '27'.

    Read the article

  • Keyboard navigation in typical WPF Business Line Application

    - by Guge
    I have a WPF business line application with a tabbed userinterface, menus and toolbars. The application must be navigable through a keyboard, some users like to minimize mouse use. I have thrown together the included XAML sample to illustrate the problem of keyboard navigation. Using the tab key I can only get to the menu, and then to the toolbar. I have tried various attached properties for KeyboardNavigation and FocusManager, but I have not succeeded in the following goals: Navigate to the contents of the first tabpage using the keyboard. Disable tab key navigation from tabpage to menu and toolbar. Change tabpage using Ctrl-Tab. <Window x:Class="WpfApplication4.MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Title="MainWindow" Height="408" Width="569" > <DockPanel> <Menu DockPanel.Dock="Top"> <MenuItem Header="_File"> <MenuItem Header="Open"/> </MenuItem> <MenuItem Header="_Edit"></MenuItem> </Menu> <ToolBarTray DockPanel.Dock="Top"> <ToolBar> <Label Target="{Binding ElementName=SearchBox}"> _Search </Label> <TextBox Name="SearchBox" Width="80"></TextBox> <Button>Search</Button> </ToolBar> </ToolBarTray> <StatusBar DockPanel.Dock="Bottom"> Statusbar here </StatusBar> <TabControl> <TabItem Header="File 1"> <WrapPanel> <Button>Click</Button> <CheckBox>Check</CheckBox> <Slider Minimum="0" Maximum="100" Width="150"/> </WrapPanel> </TabItem> <TabItem Header="File 2"> </TabItem> <TabItem Header="File 3"> </TabItem> </TabControl> </DockPanel>

    Read the article

  • Tab Control Troubles

    - by VBeginner
    Best to explain with an example. TabControl has Tab1 and Tab2. I'm trying to make it so when Tab1 is selected, Button1 is visible and stays visible. When Tab2 is selected, Button1 is invisible and stays invisible. I need it to work when the Tab is clicked, not when the content area of the Tab is clicked. Thank you.

    Read the article

  • How to refresh the textbox text when tabs are Changed in WPF

    - by StonedJesus
    Well in my WPF application I am using Tab Control which has around 5 tabs. The view of each tab is a user control which I add via a tool box. Main Xaml File: <Grid> <TabControl Height="Auto" HorizontalAlignment="Stretch" Margin="0" Name="tabControl1" VerticalAlignment="Stretch" Width="Auto"> <TabItem Header="Device Control" Name="Connect"> <ScrollViewer Height="Auto" Name="scrollViewer1" Width="Auto"> <my:ConnectView Name="connectView1" /> </ScrollViewer> </TabItem> <TabItem Header="I2C"> <ScrollViewer Height="Auto" Name="scrollViewer2" Width="Auto"> <my1:I2CControlView Name="i2CControlView1" /> </ScrollViewer> </TabItem> <TabItem Header="Voltage"> <ScrollViewer Height="Auto" Name="scrollViewer3" Width="Auto"> <my2:VoltageView Name="voltageView1" /> </ScrollViewer> </TabItem> </TabControl> </Grid> If you notice each view ie.e Connect, I2C and Voltage is a user control which has a view, viewmodel and model class :) Each of these views have set of textboxes in their respective xaml files. Connect.xaml: <Grid> <Textbox Text="{Binding Box}", Name="hello" /> // Some more textboxes </Grid> I2c.xaml: <Grid> <Textbox Text="{Binding I2CBox}", Name="helI2c" /> // Some more textboxes </Grid> Voltage.xaml: <Grid> <Textbox Text="{Binding VoltBox}", Name="heVoltllo" /> // Some more textboxes </Grid>** By default I have set the text of these textboxes to some value. Lets say "12" "13" "14" respectively in my view model classes. My main requirement is to set the text of these textboxes present in each user control to get refreshed when I change the tab. Description: Lets say Connect View is displayed: Value of Textbox is 12 and I edit it and change it to 16. Now I click on I2C tab and then I go back to Connect tab, I want the textbox value to get refreshed back to the initial value i.e. 12. To be precise, is their a method called visibilitychanged() which I can write in all my user control classes, where I can set the value of these Ui components whenever tabs are changed? Please help :)

    Read the article

  • Binding one dependency property to another

    - by Gregory Dodd
    I have a custom Tab Control that I have created, but I am having an issue. I have an Editable TextBox as part of the custom TabControl View. <Controls:EditableTextControl x:Name="PageTypeName" Style="{StaticResource ResourceKey={x:Type Controls:EditableTextControl}}" Grid.Row="0" TabIndex="0" Uid="0" AutomationProperties.AutomationId="PageTypeNameTextBox" AutomationProperties.Name="PageTypeName" Visibility="{Binding ElementName=PageTabControl,Path=ShowPageType}"> <Controls:EditableTextControl.ContextMenu> <ContextMenu x:Name="TabContextMenu"> <MenuItem Header="Rename Page Type" Command="{Binding Path=PlacementTarget.EnterEditMode, RelativeSource={RelativeSource AncestorType=ContextMenu}}" AutomationProperties.AutomationId="RenamePageTypeMenuItem" AutomationProperties.Name="RenamePageType"/> <MenuItem Header="Delete Page Type" Command="{Binding Path=PageTypeDeletedCommand}" AutomationProperties.AutomationId="DeletePageTypeMenuItem" AutomationProperties.Name="DeletePageType"/> </ContextMenu> </Controls:EditableTextControl.ContextMenu> <Controls:EditableTextControl.Content> <!--<Binding Path="CurrentPageTypeViewModel.Name" Mode="TwoWay"/>--> <Binding ElementName="PageTabControl" Path="CurrentPageTypeName" Mode ="TwoWay"/> </Controls:EditableTextControl.Content> </Controls:EditableTextControl> In the Content section I am binding to a Dependency Prop called CurrentPageTypeName. This Depedency prop is part of this custom Tab Control. public static DependencyProperty CurrentPageTypeNameProperty = DependencyProperty.Register("CurrentPageTypeName", typeof(object), typeof(TabControlView)); public object CurrentPageTypeName { get { return GetValue(CurrentPageTypeNameProperty) as object; } set { SetValue(CurrentPageTypeNameProperty, value); } } In another view, where I am using the custom TabControl I then bind my property, with the actual name value, to CurrentPageTypeName property as seen below: <Views:TabControlView Grid.Row="0" Name="RunPageTabControl" TabItemsSource="{Binding RunPageTypeViewModels}" SelectedTab="{Binding Converter={StaticResource debugConverter}}" CurrentPageTypeName="{Binding Path=RunPageName, Mode=TwoWay}" TabContentTemplateSelector="{StaticResource tabItemTemplateSelector}" SelectedIndex="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type UserControl}}, Path=DataContext.SelectedTabIndex}" ShowPageType="Hidden" > <!--<Views:TabControlView.TabContentTemplate> <DataTemplate DataType="{x:Type ViewModels:RunPageTypeViewModel}"> <RunViews:RunPageTypeView/> </DataTemplate> </Views:TabControlView.TabContentTemplate>--> </Views:TabControlView> My problem is that nothing seems to be happening. It is grabbing its Content from the Itemsource, and not from my chained Dependency props. Is what I am trying even possible? If so, what have I done wrong. Thanks for looking.

    Read the article

  • How to programmatically create customcontrol and change its values in Silverlight 4

    - by user361317
    Hi! I want to create a custom tabcontrol class which has an icon before the text, and I want to be able to change the icon in the constructor of the new tabcontrol. I use implicit styles in Silverlight 4, and the custom tabcontrol should not have any xaml of its own, just the class and the implicit xaml style in my App.xaml. I cannot, however, get this to work. This is my code: <!-- Style for generic tabcontrols --> 20,0,0,0 <Style TargetType="controls:TabItem"> <Setter Property="IsTabStop" Value="False"/> <Setter Property="Background" Value="#FFDBEDFB"/> <Setter Property="BorderBrush" Value="#FFA3AEB9"/> <Setter Property="BorderThickness" Value="1"/> <Setter Property="Padding" Value="6,2,6,2"/> <Setter Property="HorizontalContentAlignment" Value="Stretch"/> <Setter Property="VerticalContentAlignment" Value="Stretch"/> <Setter Property="MinWidth" Value="5"/> <Setter Property="MinHeight" Value="5"/> <Setter Property="Template"> <Setter.Value> <ControlTemplate TargetType="controls:TabItem"> <Grid x:Name="Root" Cursor="Hand" Height="25"> <VisualStateManager.VisualStateGroups> <VisualStateGroup x:Name="CommonStates"> <VisualStateGroup.Transitions> <VisualTransition GeneratedDuration="0"/> <VisualTransition GeneratedDuration="0:0:0.1" To="MouseOver"/> </VisualStateGroup.Transitions> <VisualState x:Name="Normal"/> <VisualState x:Name="MouseOver"> <Storyboard> <DoubleAnimationUsingKeyFrames BeginTime="0" Duration="00:00:00.001" Storyboard.TargetName="FocusVisualTop" Storyboard.TargetProperty="(UIElement.Opacity)"> <SplineDoubleKeyFrame KeyTime="0" Value="0"/> </DoubleAnimationUsingKeyFrames> </Storyboard> </VisualState> <VisualState x:Name="Disabled"> <Storyboard> <DoubleAnimationUsingKeyFrames Storyboard.TargetName="DisabledVisualTopSelected" Storyboard.TargetProperty="(UIElement.Opacity)"> <SplineDoubleKeyFrame KeyTime="0" Value="1"/> </DoubleAnimationUsingKeyFrames> <DoubleAnimationUsingKeyFrames Storyboard.TargetName="DisabledVisualTopUnSelected" Storyboard.TargetProperty="(UIElement.Opacity)"> <SplineDoubleKeyFrame KeyTime="0" Value="1"/> </DoubleAnimationUsingKeyFrames> </Storyboard> </VisualState> </VisualStateGroup> <VisualStateGroup x:Name="SelectionStates"> <VisualState x:Name="Unselected"/> <VisualState x:Name="Selected"/> </VisualStateGroup> <VisualStateGroup x:Name="FocusStates"> <VisualState x:Name="Focused"> <Storyboard> <ObjectAnimationUsingKeyFrames Duration="0" Storyboard.TargetName="FocusVisualTop" Storyboard.TargetProperty="Visibility"> <DiscreteObjectKeyFrame KeyTime="0" Value="Visible"/> </ObjectAnimationUsingKeyFrames> </Storyboard> </VisualState> <VisualState x:Name="Unfocused"> <Storyboard> <ObjectAnimationUsingKeyFrames Duration="0" Storyboard.TargetName="FocusVisualElement" Storyboard.TargetProperty="Visibility"> <DiscreteObjectKeyFrame KeyTime="0" Value="Collapsed"/> </ObjectAnimationUsingKeyFrames> </Storyboard> </VisualState> </VisualStateGroup> </VisualStateManager.VisualStateGroups> <Grid x:Name="TemplateTopUnselected" Margin="1"> <Border x:Name="BorderTop" BorderThickness="1,1,1,0"> <Border x:Name="GradientTop" BorderThickness="1,1,1,0" CornerRadius="5,5,0,0"> <Border.BorderBrush> <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0"> <GradientStop Color="#FFB1CCEE" Offset="0"/> <GradientStop Color="#CCB1CCEE" Offset="1"/> </LinearGradientBrush> </Border.BorderBrush> <Border.Background> <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0"> <GradientStop Color="#FFCEE0F7" Offset="0.091"/> <GradientStop Color="#FFDEECFD" Offset="0.996"/> <GradientStop Color="White"/> </LinearGradientBrush> </Border.Background> <Grid Margin="3,3,3,2"> <Grid.RowDefinitions> <RowDefinition Height="16"/> </Grid.RowDefinitions> <Grid.ColumnDefinitions> <ColumnDefinition Width="16"/> <ColumnDefinition/> <ColumnDefinition Width="15"/> </Grid.ColumnDefinitions> <Image x:Name="TabInactiveIcon" Source="group.png" Margin="0" HorizontalAlignment="Center" VerticalAlignment="Center" Opacity="0.395"/> <ContentControl x:Name="HeaderTopUnselected" Cursor="{TemplateBinding Cursor}" Margin="3,0" FontSize="{TemplateBinding FontSize}" Foreground="#FF416AA3" IsTabStop="False" FontFamily="Tahoma" Grid.Column="1" HorizontalAlignment="Center" VerticalAlignment="Center"/> <Button x:Name="TabInactiveCloseButton" Template="{StaticResource TabItemCloseButton}" Cursor="Hand" Height="10" HorizontalAlignment="Right" Margin="0" VerticalAlignment="Top" Width="10" Content="Button" Grid.Column="2" d:LayoutOverrides="GridBox"/> </Grid> </Border> </Border> <Border x:Name="DisabledVisualTopUnSelected" IsHitTestVisible="false" Opacity="0" Background="#8CFFFFFF" CornerRadius="3,3,0,0"/> </Grid> <Border x:Name="FocusVisualElement" Margin="-1" IsHitTestVisible="false" Visibility="Collapsed" BorderBrush="#FF6DBDD1" BorderThickness="1" CornerRadius="3,3,0,0"/> <Grid x:Name="TemplateTopSelected" Margin="0,0,0,-3" Visibility="Collapsed"> <Border x:Name="BorderTop1" BorderThickness="1,1,1,0"> <Border x:Name="GradientTop1" BorderThickness="1,1,1,0" CornerRadius="5,5,0,0"> <Border.BorderBrush> <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0"> <GradientStop Color="#FFB1CCEE" Offset="0"/> <GradientStop Color="#CAB1CCEE" Offset="1"/> </LinearGradientBrush> </Border.BorderBrush> <Border.Background> <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0"> <GradientStop Color="#FFCEE0F7" Offset="0.091"/> <GradientStop Color="White" Offset="0.974"/> <GradientStop Color="White"/> </LinearGradientBrush> </Border.Background> <Grid Margin="3,3,3,2"> <Grid.RowDefinitions> <RowDefinition Height="16"/> </Grid.RowDefinitions> <Grid.ColumnDefinitions> <ColumnDefinition Width="16"/> <ColumnDefinition/> <ColumnDefinition Width="15"/> </Grid.ColumnDefinitions> <Image x:Name="TabActiveIcon" Source="user.png" Margin="0" HorizontalAlignment="Center" VerticalAlignment="Center"/> <ContentControl x:Name="HeaderTopSelected" Cursor="{TemplateBinding Cursor}" Margin="3,0" FontSize="{TemplateBinding FontSize}" Foreground="#FF416AA3" IsTabStop="False" FontFamily="Tahoma" FontWeight="Bold" Grid.Column="1" HorizontalAlignment="Center" VerticalAlignment="Center"/> <Button x:Name="TabActiveCloseButton" Template="{StaticResource TabActiveCloseButton}" Cursor="Hand" Height="10" HorizontalAlignment="Right" Margin="0" VerticalAlignment="Top" Width="10" Content="Button" Grid.Column="2" d:LayoutOverrides="GridBox"/> </Grid> </Border> </Border> <Border x:Name="FocusVisualTop" Margin="-2,-2,-2,0" IsHitTestVisible="false" Visibility="Collapsed" BorderThickness="1,1,1,0" CornerRadius="3,3,0,0"/> <Border x:Name="DisabledVisualTopSelected" Margin="-2,-2,-2,0" IsHitTestVisible="false" Opacity="0" Background="#8CFFFFFF" CornerRadius="3,3,0,0"/> </Grid> </Grid> </ControlTemplate> </Setter.Value> </Setter> </Style> and my class public class ClosableTabItem : TabItem { public static readonly DependencyProperty TabIconProperty = DependencyProperty.RegisterAttached("TabInactiveIcon", typeof(Image), typeof(ClosableTabItem), null); public Image TabIcon { get { return (Image)GetValue(ClosableTabItem.TabIconProperty); } set { SetValue(ClosableTabItem.TabIconProperty, value); } } public ClosableTabItem(string header, ContentControl content, TabItemIcons icon) { // I need to be able to set the header, content and icon here } private Image GetTabIcon(TabItemIcons icon) { Image img = new Image(); switch (icon) { case TabItemIcons.User: img.Source = new BitmapImage(new Uri("/icons/user.png", UriKind.Relative)); break; case TabItemIcons.Group: img.Source = new BitmapImage(new Uri("/icons/group.png", UriKind.Relative)); break; default: break; } return img; } } This is driving me nuts, and I can't find any examples where anyone has done this without having a xaml page for the custom tab. Is this even possible? Can someone point me in the right direction? Cheers! - jonah

    Read the article

  • How to properly structure a project in winform?

    - by user850010
    A while ago I started to create a winform application and at that time it was small and I did not give any thought of how to structure the project. Since then I added additional features as I needed and the project folder is getting bigger and bigger and now I think it is time to structure the project in some way, but I am not sure what is the proper way, so I have few questions. How to properly restructure the project folder? At the moment I am thinking of something like this: Create Folder for Forms Create Folder for Utility classes Create Folder for Classes that contain only data What is the naming convention when adding classes? Should I also rename classes so that their functionality can be identified by just looking at their name? For example renaming all forms classes, so that their name ends with Form. Or is this not necessary if special folders for them are created? What to do, so that not all the code for main form ends up in Form1.cs Another problem I encountered is that as the main form is getting more massive with each feature I add, the code file (Form1.cs) is getting really big. I have for example a TabControl and each tab has bunch of controls and all the code ended up in Form1.cs. How to avoid this? Also, Do you know any articles or books that deal with these problems?

    Read the article

  • Visual WebGui launches a new prize-winning challenge for developers

    - by Webgui
    Gizmox is announcing a ListView Challenge where developers can participate by creating and submitting their own implementations of the new extended ListView. "its quite amazing what you can do with it. It opens a lot of new ways to present data in a better and more userfriendly way," says one of the VWG community members who built a three level hierarchal ListView. Watch the hierarchal ListView demo by Visualizer Those ListView implementations will be reviewed and rated and the winner will win a free Professional Studio license $750 worth. The 5 top rated codes will entitle their developers for a cool new T-shirt. The new v6.4 introduces new capabilities with its extended ListView Control. Enter the Challenge The Collapsible Panel enhancement of the ListView Control, along with the Column Type Control, open up the possibilities for potential usage of the ListView control for data display, data entry and as the Collapsible Panel can contain whatever control you like, it can as well contain other ListView controls, thus making it possible to create Hierarchial ListView display of unlimited number of levels. The first enhancement is the introduction of a new column type Control which opens up the possibility for a ListView cell to contain controls like CheckBox, ComboBox, ListBox or even TabControl, Form or another ListView as the contents of that particular cell. This means that the ListView is no longer a display-only control, but has the full potential of being a full blown data entry control as well. The second major enhancement is the introduction of ListViewPanelItem. The ListViewPanelItem behaves exactly the same as it‘s predecessor, the ListViewItem, and in additon it has a Panel Control attached to it, seperate panel for each row in the ListView. This new Panel can be either expanded (visible) or not (hidden) and when expanded, will fill the full width of the ListView, but has adjustable height. Watch a webcast about the extended ListView

    Read the article

  • WPF Binding Error reported when Binding appears to work fine

    - by Noldorin
    I am trying to create a custom TabItem template/style in my WPF 4.0 application (using VS 2010 Pro RTM), but inspite of everything seeming to work correctly, I am noticing a binding error in the trace window. The resource dictionary XAML I use to style the TabItems of a TabControl is given in full here. (Just create a simple TabControl with several items and apply the given ResourceDictionary to test it out.) Specifically, the error is occurring due to the following line (discovered through trial and error testing, since Visual Studio isn't actually reporting it at design tim <TranslateTransform X="{Binding ActualWidth, ElementName=leftSideBorderPath}"/> The full error given in the trace (Ouput window) is the following: System.Windows.Data Error: 2 : Cannot find governing FrameworkElement or FrameworkContentElement for target element. BindingExpression:Path=ActualWidth; DataItem=null; target element is 'TranslateTransform' (HashCode=35345840); target property is 'X' (type 'Double') The error occurs on load and is repeated 5 times then (note that I have 3 tab items in my example). It also occurs consistently and repeatedly whenever for the Window is resized, for example - filling the Output window. Perhaps every time the TabItem layout is updated? And again, though it is not reported, the error very much seems to be due to the fact that I am binding to any element at all, not specifically leftSideBorderPath or the the ActualWidth propertry. For example, changing this line to the following fixes things. <TranslateTransform X="25"/> Unfortunately, hard-coding the value isn't really an option. This issue seems very strange to me in that the binding does appear to be giving the correct results. (Inspecting the X value of the TranslateTransform at runtime clearly shows the correct bound value, and the ClipGeometry when viewed is exactly what it hsould be.) Neither Visual Studio nor WPF seems to be giving me any more information on the cause of the error perhaps (setting PresentationTraceSources.TraceLevel to High doesn't help), yet the fact that things are working despite the error being reported inclines me to think that this is some fringe-case WPF bug. As a side note, the Visual Studio WPF designer and XAML editor are giving me a problem with the following line: <PathGeometry Figures="{Binding Source={StaticResource TabSideFillFigures}}"/> Although WPF (at runtime) is perfectly happy binding Figures to the TabSideFillFigures string, with the Binding enforcing the use of the TypeConverter, the XAML editor and WPF designer are complaining. All the XAML code for the ControlTemplate is underlined and I get the following errors in the Error List: Error 9 '{DependencyProperty.UnsetValue}' is not a valid value for the 'System.Windows.Controls.Control.Template' property on a Setter. C:\Users\Alex\Documents\Visual Studio 2010\Projects\Ircsil\devel\Ircsil\MainWindow.xaml 1 1 Ircsil Error 10 Object reference not set to an instance of an object. C:\Users\Alex\Documents\Visual Studio 2010\Projects\Ircsil\devel\Ircsil\Skins\Default\MainSkin.xaml 58 17 Ircsil Again, to repeat, everything works perfectly well at runtime, which is what makes this particularly odd... Could someone perhaps shed some light on these issues, in particular the first (which seems to be a potential WPF bug), and the latter (which seems to be a Visual Studio bug). Any sort of feedback or suggestions would be much appreciated!

    Read the article

  • Databinding to ObservableCollection in a different UserControl - how to preserve current selections?

    - by Dave
    Scope of question expanded on 2010-03-25 I ended up figuring out my problem, but here's a new problem that came up as a result of solving the original question, because I want to be able to award the bounty to someone!!! Once I figured out my problem, I soon found out that when the ObservableCollection updates, the databound ComboBox has its contents repopulated, but most of the selections have been blanked out. I assume that in this case, MVVM is going to make it difficult for me to remember the last selected item. I have an idea, but it seems a little nasty. I'll award the bounty to whomever comes up with a nice solution for this! Question re-written on 2010-03-24 I have two UserControls, where one is a dialog that has a TabControl, and the other is one that appears within said TabControl. I'll just call them CandyDialog and CandyNameViewer for simplicity's sake. There's also a data management class called Tracker that manages information storage, which for all intents and purposes just exposes a public property that is an ObservableCollection. I display the CandyNameViewer in CandyDialog via code behind, like this: private void CandyDialog_Loaded( object sender, RoutedEventArgs e) { _candyviewer = new CandyViewer(); _candyviewer.DataContext = _tracker; candy_tab.Content = _candyviewer; } The CandyViewer's XAML looks like this (edited for kaxaml): <Page xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"> <Page.Resources> <DataTemplate x:Key="CandyItemTemplate"> <Grid> <Grid.ColumnDefinitions> <ColumnDefinition Width="120"></ColumnDefinition> <ColumnDefinition Width="150"></ColumnDefinition> </Grid.ColumnDefinitions> <TextBox Grid.Column="0" Text="{Binding CandyName}" Margin="3"></TextBox> <!-- just binding to DataContext ends up using InventoryItem as parent, so we need to get to the UserControl --> <ComboBox Grid.Column="1" SelectedItem="{Binding SelectedCandy, Mode=TwoWay}" ItemsSource="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type UserControl}}, Path=DataContext.CandyNames}" Margin="3"></ComboBox> </Grid> </DataTemplate> </Page.Resources> <Grid> <ListBox DockPanel.Dock="Top" ItemsSource="{Binding CandyBoxContents, Mode=TwoWay}" ItemTemplate="{StaticResource CandyItemTemplate}" /> </Grid> </Page> Now everything works fine when the controls are loaded. As long as CandyNames is populated first, and then the consumer UserControl is displayed, all of the names are there. I obviously don't get any errors in the Output Window or anything like that. The issue I have is that when the ObservableCollection is modified from the model, those changes are not reflected in the consumer UserControl! I've never had this problem before; all of my previous uses of ObservableCollection updated fine, although in those cases I wasn't databinding across assemblies. Although I am currently only adding and removing candy names to/from the ObservableCollection, at a later date I will likely also allow renaming from the model side. Is there something I did wrong? Is there a good way to actually debug this? Reed Copsey indicates here that inter-UserControl databinding is possible. Unfortunately, my favorite Bea Stollnitz article on WPF databinding debugging doesn't suggest anything that I could use for this particular problem.

    Read the article

  • WPF: Focus in a Window and UserControl

    - by Echilon
    I'm trying to get a UserControl to tab properly and am baffled. The logical tree looks like this. |-Window -Grid -TabControl -TabItem -StackPanel -MyUserControl |-StackPanel -GroupBox -Grid -ComboBox -Textbox1 -Textbox2 Everything works fine, except when the visibility converter for the ComboBox returns Visibility.Collapsed (don't allow user to change database mode), then when textbox1 is selected, instead of being able to tab through the controls in the UserControl, the focus shifts to a button declared at the bottom of the window. Nothing else apart from the controls displayed has TabIndex or FocusManager properties set. I'm banging my head against a brick wall and I must be missing something. I've tried IsFocusScope=True/False, played with FocusedElement and nothing works if that ComboBox is invisible (Visibility.Collapsed). <Window x:Class="MyNamespace.Client.WinInstaller" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" FocusManager.FocusedElement="{Binding ElementName=tabWizard}"> <Window.Resources> <props:Settings x:Key="settings" /> </Window.Resources> <Grid Grid.IsSharedSizeScope="True"> <!-- row and column definitions omitted --> <loc:SmallHeader Grid.Row="0" x:Name="headerBranding" HeaderText="Setup" /> <TabControl x:Name="tabWizard" DataContext="{StaticResource settings}" SelectedIndex="0" FocusManager.IsFocusScope="True"> <TabItem x:Name="tbStart" Height="0"> <StackPanel> <TextBlock Text="Database Mode"/> <loc:DatabaseSelector x:Name="dbSelector" AllowChangeMode="False" TabIndex="1" AvailableDatabaseModes="SQLServer" IsPortRequired="False" DatabaseMode="{Binding Default.DbMode,Mode=TwoWay,UpdateSourceTrigger=PropertyChanged}" DatabasePath="{Binding Default.DatabasePath,Mode=TwoWay,UpdateSourceTrigger=PropertyChanged}"/> </StackPanel> </TabItem> ... The top of the user control is below: <UserControl x:Class="MyNamespace.Client.DatabaseSelector" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" x:Name="root" FocusManager.IsFocusScope="True" FocusManager.FocusedElement="{Binding ElementName=cboDbMode}"> <UserControl.Resources> <conv:DatabaseModeIsFileBased x:Key="DatabaseModeIsFileBased"/> <BooleanToVisibilityConverter x:Key="BooleanToVisibilityConverter"/> </UserControl.Resources> <StackPanel DataContext="{Binding}"> <GroupBox> <Grid> <!-- row and column definitions omitted --> <Label Content="Database Mode"/> <ComboBox x:Name="cboDbMode" SelectedValue="{Binding ElementName=root,Path=DatabaseMode,Mode=TwoWay,UpdateSourceTrigger=PropertyChanged}" DisplayMemberPath="Value" SelectedValuePath="Key" TabIndex="1" Visibility="{Binding AllowChangeMode,ElementName=root,Converter={StaticResource BooleanToVisibilityConverter}}" /> <!-- AllowChangeMode is a DependencyProperty on the UserControl --> <Grid><!-- row and column definitions omitted --> <Label "Host"/> <TextBox x:Name="txtDBHost" Text="{Binding ElementName=root,Path=DatabaseHost,Mode=TwoWay,UpdateSourceTrigger=PropertyChanged}" TabIndex="2" /> <TextBox x:Name="txtDBPort" Text="{Binding ElementName=root,Path=DatabasePortString,Mode=TwoWay,UpdateSourceTrigger=PropertyChanged}" TabIndex="3" />

    Read the article

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