Search Results

Search found 2453 results on 99 pages for 'xaml'.

Page 18/99 | < Previous Page | 14 15 16 17 18 19 20 21 22 23 24 25  | Next Page >

  • Howto bind a RoutedCommand in a child?

    - by Wouter
    I am having trouble binding a Command that is generated up the UI tree to a control. The following example illustrates my point, the CommandBinding in Grid does not act on the InputBindings in Window. Maybe I do not understand the point of commands, but I would like to have a nice solution for child controls to act on user input on the Window (any control on the Window). <Window x:Class="SilverFit.Menu.Wpf.WpfWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"> <Window.InputBindings> <KeyBinding Command="Close" Key="Escape"/> <MouseBinding Command="Close" MouseAction="RightClick" /> </Window.InputBindings> <Grid Name="grid"> <Grid.CommandBindings> <CommandBinding Command="Close" Executed="Close"/> </Grid.CommandBindings> </Grid> </Window>

    Read the article

  • Silverlight 4.0: DataTemplate Error

    - by xscape
    Im trying to get the specific template in my resource dictionary. This is my resource dictionary <ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:view="clr-namespace:Test.Layout.View" xmlns:toolkit="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Toolkit" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"><DataTemplate x:Key="LeftRightLayout"> <toolkit:DockPanel> <view:SharedContainerView toolkit:DockPanel.Dock="Left"/> <view:SingleContainerView toolkit:DockPanel.Dock="Right"/> </toolkit:DockPanel> </DataTemplate> However when it gets to XamlReader.Load private static ResourceDictionary GetResource(string resourceName) { ResourceDictionary resource = null; XDocument xDoc = XDocument.Load(resourceName); resource = (ResourceDictionary)XamlReader.Load(xDoc.ToString(SaveOptions.None)); return resource; } The type 'SharedContainerView' was not found because 'clr-namespace:Test.Layout.View' is an unknown namespace. [Line: 4 Position: 56]

    Read the article

  • Problem using Blend 3 Interaction.Behaviours in VS2010

    - by Andre Luus
    There seems to be a problem with support for the Interactivity namespace of Blend 3 in the VS2010 xaml editor. I have the following installed: VS2010 Blend 3 + Blend 3 SDK I am trying to compile a demo project that is targeted at .Net 4 Client Profile and has a reference to System.Windows.Interactivity (in the Blend 3 folder). In the object browser everything appears to be fine. I can also access Interaction.Behaviours from code-behind, but if I put the namespace xmlns:i="http://schemas.microsoft.com/expression/2010/interactivity" in the xaml file and try to use it, the intellisense is blank. If I copy something in there anyway, the compiler says: The tag 'Interaction.Behaviors' does not exist in XML namespace 'http://schemas.microsoft.com/expression/2010/interactivity'. Do I need to install Blend 4 RC or something?

    Read the article

  • Is it possible to compile Silverlight controls project with Nant?

    - by Vish
    Hi all, I am attempting to compile my Silverlight control project with Nant without luck. Since my project contains XAML files, I am not sure if Nant is capable of generating the .g.cs files from the XAML file to be compiled into the project. I have come across posts where people suggest using the MsBuild task. Is there a way to avoid using the MsBuild task and compile the project using just Nant? I am not against using the MsBuild task. But would prefer to not use it if possible. Thank You, Vish

    Read the article

  • WPF Combobox binding Question

    - by ebattulga
    I have a 2 Table. Product ProductName CategoryID Category ID CategoryName I'm filling combobox to table named 'category'. Code Product currentProduct=datacontext.products.FirstOrDefault(); this.datacontext=currentProduct; combobox1.Itemssource=datacontext.categories; XAML <Textbox Text="{Binding Path=ProductName}"></Textbox> <Combobox x:Name="combobox1" SelectedItem="Binding Path=CategoryID"></Combobox> When click save button, I'm doing datacontext.SubmitChanges() ProductName changed. But CategoryID not changed. My target is when i select from combobox, selected category ID set to CategoryID of currentProduct. (like currentProduct.CategoryID=(Category as combobox1.SelectedItem).ID) How to do is from xaml?

    Read the article

  • WPF Application that only has a tray icon

    - by Michael Stum
    I am a total WPF newbie and wonder if anyone could give me some pointers how to write an application that starts minimized to tray. The idea is that it periodically fetches an RSS Feed and creates a Toaster-Popup when there are new feeds. The Application should still have a Main Window (essentially just a list containing all feed entries), but that should be hidden by default. I have started reading about XAML and WPF and I know that the StartupUri in the App.xaml has to point to my main window, but I have no idea what the proper way is to do the SysTray icon and hide the main window (this also means that when the user minimizes the window, it should minimize to tray, not to taskbar). Any hints?

    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

  • Silverlight 3 Application Background

    - by Rich Blumer
    I am new to Silverlight development. I have created a nice png file in Expression Design. I would like to use this png file as the background for my application. When I set the Stretch property to fill, it does not fill the entire page like I think it should. Here's the xaml: <Grid x:Name="LayoutRoot"> <Grid.Background> <ImageBrush ImageSource="IgniteTechDesign.png"/> </Grid.Background> <Border x:Name="ContentBorder"> <navigation:Frame x:Name="ContentFrame" Style="{StaticResource ContentFrameStyle}" Source="/Home" Navigated="ContentFrame_Navigated" NavigationFailed="ContentFrame_NavigationFailed"> <navigation:Frame.UriMapper> <uriMapper:UriMapper> <uriMapper:UriMapping Uri="" MappedUri="/Views/Home.xaml"/> <uriMapper:UriMapping Uri="/{pageName}" MappedUri="/Views/{pageName}.xaml"/> </uriMapper:UriMapper> </navigation:Frame.UriMapper> </navigation:Frame> </Border> <Grid x:Name="NavigationGrid" Style="{StaticResource NavigationGridStyle}"> <Border x:Name="BrandingBorder" Style="{StaticResource BrandingBorderStyle}"> <StackPanel x:Name="BrandingStackPanel" Style="{StaticResource BrandingStackPanelStyle}"> <ContentControl Style="{StaticResource LogoIcon}"/> <TextBlock x:Name="ApplicationNameTextBlock" Style="{StaticResource ApplicationNameStyle}" Text="Application Name"/> </StackPanel> </Border> <Border x:Name="LinksBorder" Style="{StaticResource LinksBorderStyle}"> <StackPanel x:Name="LinksStackPanel" Style="{StaticResource LinksStackPanelStyle}"> <HyperlinkButton x:Name="Link1" Style="{StaticResource LinkStyle}" NavigateUri="/Home" TargetName="ContentFrame" Content="home"/> <Rectangle x:Name="Divider1" Style="{StaticResource DividerStyle}"/> <HyperlinkButton x:Name="Link2" Style="{StaticResource LinkStyle}" NavigateUri="/About" TargetName="ContentFrame" Content="about"/> </StackPanel> </Border> </Grid> </Grid> Thanks in advance.

    Read the article

  • Silverlight layout Best Practices

    - by JustSmith
    I'm writing a fairly big interface using Silverlight. As I progress, the xaml file is getting fairly big and is becoming proportionally uglier. Questions Are there any resources out there to make the xaml more readable? For example, how would I display the order of attributes (e.g. height and Width first) so that it looks the most tidy? Another issue is that there are multiple ways to implement an interface with grids and stack panels. Is there a preferred approach when using one or the other? I am looking for advice and links to other resources that can be used as examples.

    Read the article

  • How do bind a List<object> to a DataGrid in Silverlight?

    - by Ben McCormack
    I'm trying to create a simple Silverlight application that involves parsing a CSV file and displaying the results in a DataGrid. I've configured my application to parse the CSV file to return a List<CSVTransaction> that contains properties with names: Date, Payee, Category, Memo, Inflow, Outflow. The user clicks a button to select a file to parse, at which point I want the DataGrid object to be populated. I'm thinking I want to use data binding, but I can't seem to figure out how to get the data to show up in the grid. My XAML for the DataGrid looks like this: <data:DataGrid IsEnabled="False" x:Name="TransactionsPreview"> <data:DataGrid.Columns> <data:DataGridTextColumn Header="Date" Binding="{Binding Date}" /> <data:DataGridTextColumn Header="Payee" Binding="{Binding Payee}"/> <data:DataGridTextColumn Header="Category" Binding="{Binding Category}"/> <data:DataGridTextColumn Header="Memo" Binding="{Binding Memo}"/> <data:DataGridTextColumn Header="Inflow" Binding="{Binding Inflow}"/> <data:DataGridTextColumn Header="Outflow" Binding="{Binding Outflow}"/> </data:DataGrid.Columns> </data:DataGrid> The code-behind for the xaml.cs file looks like this: private void OpenCsvFile_Click(object sender, RoutedEventArgs e) { try { CsvTransObject csvTO = new CsvTransObject.ParseCSV(); //This returns a List<CsvTransaction> and passes it //to a method which is supposed to set the DataContext //for the DataGrid to be equal to the list. BindCsvTransactions(csvTO.CsvTransactions); TransactionsPreview.IsEnabled = true; MessageBox.Show("The CSV file has a valid header and has been loaded successfully."); } catch (Exception ex) { MessageBox.Show(ex.Message); } } private void BindCsvTransactions(List<CsvTransaction> listYct) { TransactionsPreview.DataContext = listYct; } My thinking is to bind the CsvTransaction properties to each DataGridTextColumn in the XAML and then set the DataContext for the DataGrid to the List<CsvTransaction at run-time, but this isn't working. Any ideas about how I might approach this (or do it better)?

    Read the article

  • WPF: Bind/Apply Filter on Boolean Property

    - by Julian Lettner
    I want to apply a filter to a ListBox accordingly to the IsSelected property of a CheckBox. At the moment I have something like this. XAML <CheckBox Name="_filterCheckBox" Content="Filter list" Checked="ApplyFilterHandler"/> <ListBox ItemsSource="{Binding SomeItems}" /> CodeBehind public ObservableCollection<string> SomeItems { get; private set; } private void ApplyFilterHandler(object sender, RoutedEventArgs e) { if (_filterCheckBox.IsChecked.Value) CollectionViewSource.GetDefaultView(SomeItems).Filter += MyFilter; else CollectionViewSource.GetDefaultView(SomeItems).Filter -= MyFilter; } private bool MyFilter(object obj) { return ... } It works but this solution feels like the old-fashioned way (Windows Forms). Question: Is it possible to achieve this with Bindings / in XAML? Thanks for your time.

    Read the article

  • Escape from DataContext

    - by grayscales
    I have a window that get its data from another class that is passed as DataContext. But I now also want to do data binding within the window. The window looks as follows: <Window x:Class="WpfApplication1.Window1" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Title="Window1" Height="300" Width="300"> <StackPanel> <TextBlock Text="{Binding UserName}" /> <TextBlock x:Name="TestTextBlock">Hello World</TextBlock> <TextBlock x:Name="TestTextBlock2" Text="{Binding ElementName=TestTextBlock,Path=Text}" /> </StackPanel> </Window> The binding between the text blocks TestTextBlock and TestTextBlock2 works fine, but only until I change the DataContext-property of the window. How can I bind between those two textblocks so that changing the DataContext will not break the data binding? Thanks in advance, Stefan

    Read the article

  • Binding to static property

    - by Anthony Brien
    I'm having a hard time binding a simple static string property to a text box. Here's the class with the static property: public class VersionManager { private static string filterString; public static string FilterString { get { return filterString; } set { filterString = value; } } } In my xaml, I just want to bind this static property to a text box: <TextBox> <TextBox.Text> <Binding Source="{x:Static local:VersionManager.FilterString}"/> </TextBox.Text> </TextBox> Everything compiles, but at run time, I get the following exception: Cannot convert the value in attribute 'Source' to object of type 'System.Windows.Markup.StaticExtension'. Error at object 'System.Windows.Data.Binding' in markup file 'BurnDisk;component/selectversionpagefunction.xaml' Line 57 Position 29. Any idea what I'm doing wrong?

    Read the article

  • WPF: Binding with title and subitems

    - by John
    I am having some issues trying to learn WPF. What I am trying to do is to bind a class that has a string and an array of strings. I would like to bind the string as the title and array as the contents of an expander, but I am having difficulties. What am I missing to make this work? Any help would be appreciated, TIA. This is the code I have thus far: XAML <Window x:Class="WpfApplication1.Window1" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Title="Window1" Height="300" Width="300"> <Grid> <ListBox Grid.Column="0" Name="lbTopics" ItemsSource="{Binding}"> <ListBox.ItemTemplate> <DataTemplate> <Expander Header="{Binding Path=TopicName}" > <Expander.Content> <ListBox> <ListBox.ItemTemplate> <DataTemplate> <Label Content="{Binding Path=(ItemName)}" Width="120px" Height="32px" Foreground="Black" /> </DataTemplate> </ListBox.ItemTemplate> </ListBox> </Expander.Content> </Expander> </DataTemplate> </ListBox.ItemTemplate> </ListBox> </Grid> C# namespace WpfApplication1 { public partial class Window1 : Window { public Window1() { InitializeComponent(); lbTopics.DataContext = new Topics(); } } public class Topics : ObservableCollection<Topic> { public Topics() { for (int i = 0; i < 10; i++) { this.Add(new Topic(i)); } } } public class Topic { public Topic(int i) { TopicName = "Topic " + i; ItemName = new List<string>(10); for (int j = 0; j < 10; j++) { ItemName.Add(i + " - Item " + j); } } public string TopicName { get; set; } public List<string> ItemName { get; set; } } }

    Read the article

  • How to call window developed in C# through FindWindow api.

    - by Sagar Mane
    Hello All, I am new to C# and xaml code. I have one sample code which implemented in C#. when I have reviewed xaml file I got <Window x:Class="test.MainWindow">. So does test.MainWindow indicate the class name for this window. I am trying to invoke this window from other application which is developed in win 32. I am trying to pass this class name to FindWindow("test.MainWindow",NULL) ,but it fails. does anything missing over there. how I can change the class name of window developed in C#? Thanks, Sagar

    Read the article

  • XamlXmlReader.Read() does not yield matching XamlNodeType.StartObject and XamlNodeType.EndObject on

    - by Yuval
    Hi, I am trying to parse a valid xaml file using the XamlXmlReader. It looks like it is 'skipping' some elements when when Read() is called. for example on the following xaml snippet: <UserControl.Resources> <Converters:AnyDbTypeToDisplayNameConverter x:Key="anyDbTypeToDisplayNameConverter" /> </UserControl.Resources> when reading I first get a XamlNodeType.StartObject on UserControl.Resources - makes sense then another XamlNodeType.StartObject on Converters - also cool. but then i do not get a XamlNodeType.EndObject on the Converters and immediately jump to the next line and does not report a XamlNodeType.StartObject. Any Idea if this is working as design ? looks like a bug to me

    Read the article

  • TreeView binding issue in WPF

    - by Michael Stoll
    Consider the following data structure: List<Person> People; class Person { List<Car> Cars; List<Hobby> Hobbies; } I want to bind a TreeView to this structure. And it should look like this: People > Frank > Cars > BMW > Ford > Hobbies > Tennis > Golf > Jane > Cars > Hobbies How can this be achieved in XAML? This is a follow up question to binding-a-treeview-with-contextmenu-in-xaml

    Read the article

  • WPF: Setting DataContext of a UserControl with Binding not working in XAML

    - by Grant Crofton
    Hi, I'm trying to get my first WPF app working using MVVM, and I've hit a little binding problem. The setup is that I have a view & viewModel which holds User details (the parent), and to try and keep things simple I've put a section of that view into a separate view & viewModel (the child). The child view is defined as a UserControl. The issue I'm having is how to set the DataContext of the child view (the UserControl). My parent ViewModel has a property which exposes the child ViewModel, like so: class ParentViewModel: INotifyPropertyChanged { public ChildViewModel childViewModel { get; set; } //... } In the XAML for my parent view (which has it's DataContext set to the ParentViewModel), I try to set the DataContext of the child view as follows: <views:ChildView x:Name="ChildView" DataContext="{Binding childViewModel}"/> However, this doesn't work. The DataContext of the child view is set to the same DataContext as the parent view (i.e. the ParentViewModel), as if I wasn't setting it at all. I also tried setting the DataContext in the child view itself, which also doesn't work: <UserControl x:Class="DietRecorder.Client.View.ChildView" DataContext="childViewModel" I have found a couple of ways around this. In the child view, I can bind everything by including the ChildViewModel in the path: <SomeControl Visibility="{Binding Path=childViewModel.IsVisible}"> but I don't want the child view to have this level of awareness of the hierarchy. Setting the DataContext in code also works - however, I have to do this after showing the parent view, otherwise the DataContext just gets overwritten when I call Show(): parentView.Show(); parentView.ChildView.DataContext = parentViewModel.childViewModel; This code also makes me feel uneasy, what with the LOD violation and all. It's just the DataContext that seems to be the problem - I can bind other things in the child, for example I tried binding the FontSize to an int property just to test it: <views:ChildView x:Name="ChildView" FontSize="{Binding Path=someVal}"/> And that works fine. But I'm sure binding the DataContext should work - I've seen similar examples of this kind of thing. Have I missed something obvious here? Is there a reason this won't work? Is there a spelling mistake somewhere? (I renamed things for your benefit so you won't be able to help me there anyway). Any thoughts welcome. Thanks, Grant

    Read the article

  • WPF Xaml Custom Styling Selected Item Style in a ListBox

    - by John Batdorf
    I have a list box that scrolls images horizontally. I have the following XAML I used blend to create it. It originally had a x:Key on the Style TaregetType line, MSDN said to remove it, as I was getting errors on that. Now I'm getting this error: Error 3 Operation is not valid while ItemsSource is in use. Access and modify elements with ItemsControl.ItemsSource instead. I don't understand how to apply all of this junk that way, I've tried several thing, nothing is working. My goal is to have the selected item's background be white, not blue. Seems like a lot of work for something so small! Thanks. <ListBox ItemsSource="{Binding Source={StaticResource WPFApparelCollection}}" Grid.Row="1" Margin="2,26,2,104" ScrollViewer.VerticalScrollBarVisibility="Hidden" ScrollViewer.HorizontalScrollBarVisibility="Hidden" SelectionMode="Single" x:Name="list1" MouseLeave="List1_MouseLeave" MouseMove="List1_MouseMove" Style="{DynamicResource ListBoxStyle1}" > <Style TargetType="{x:Type ListBoxItem}"> <Setter Property="Background" Value="Transparent"/> <Setter Property="HorizontalContentAlignment" Value="{Binding Path=HorizontalContentAlignment, RelativeSource={RelativeSource AncestorType={x:Type ItemsControl}}}"/> <Setter Property="VerticalContentAlignment" Value="{Binding Path=VerticalContentAlignment, RelativeSource={RelativeSource AncestorType={x:Type ItemsControl}}}"/> <Setter Property="Padding" Value="2,0,0,0"/> <Setter Property="Template"> <Setter.Value> <ControlTemplate TargetType="{x:Type ListBoxItem}"> <Border x:Name="Bd" SnapsToDevicePixels="true" Background="{TemplateBinding Background}" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" Padding="{TemplateBinding Padding}"> <ContentPresenter HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" VerticalAlignment="{TemplateBinding VerticalContentAlignment}" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"/> </Border> <ControlTemplate.Triggers> <Trigger Property="IsSelected" Value="true"> <Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.HighlightTextBrushKey}}"/> <Setter Property="Background" TargetName="Bd" Value="#FFFFFFFF"/> </Trigger> <MultiTrigger> <MultiTrigger.Conditions> <Condition Property="IsSelected" Value="true"/> <Condition Property="Selector.IsSelectionActive" Value="false"/> </MultiTrigger.Conditions> <Setter Property="Background" TargetName="Bd" Value="{DynamicResource {x:Static SystemColors.ControlBrushKey}}"/> <Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.ControlTextBrushKey}}"/> </MultiTrigger> <Trigger Property="IsEnabled" Value="false"> <Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.GrayTextBrushKey}}"/> </Trigger> </ControlTemplate.Triggers> </ControlTemplate> </Setter.Value> </Setter> </Style> <ListBox.ItemsPanel> <ItemsPanelTemplate> <VirtualizingStackPanel Orientation="Horizontal" IsItemsHost="True" /> </ItemsPanelTemplate> </ListBox.ItemsPanel> <ListBox.ItemTemplate> <DataTemplate> <Image Source="{Binding Image}" /> </DataTemplate> </ListBox.ItemTemplate> </ListBox>

    Read the article

  • WPF MenuItem.Command binding to ElementName results to System.Windows.Data Error: 4 : Cannot find so

    - by e28Makaveli
    I have the following XAML: <UserControl x:Class="EMS.Controls.Dictionary.TOCControl" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:vm="clr-namespace:EMS.Controls.Dictionary.Models" xmlns:diagnostics="clr-namespace:System.Diagnostics;assembly=WindowsBase" x:Name="root" > <TreeView x:Name="TOCTreeView" Background="White" Padding="3,5" ContextMenuOpening="TOCTreeView_ContextMenuOpening" ItemsSource="{Binding Children}" BorderBrush="{x:Null}" > <TreeView.ItemTemplate> <HierarchicalDataTemplate ItemsSource="{Binding Path=Children, Mode=OneTime}"> <Grid > <Grid.ColumnDefinitions> <ColumnDefinition Width="Auto"/> <!--<ColumnDefinition Width="Auto"/>--> <ColumnDefinition Width="*"/> </Grid.ColumnDefinitions> <!--<CheckBox VerticalAlignment="Center" IsChecked="{Binding IsVisible}"/>--> <ContentPresenter Grid.Column="0" Height="16" Width="20" Content="{Binding LayerRepresentation}" /> <!--<ContentPresenter Grid.Column="1" > <ContentPresenter.Content> Test </ContentPresenter.Content> </ContentPresenter>--> <TextBlock Grid.Column="2" FontWeight="Normal" Text="{Binding Path=Alias, Mode=OneWay}" > <ToolTipService.ToolTip> <TextBlock Text="{Binding Description}" TextWrapping="Wrap"/> </ToolTipService.ToolTip> </TextBlock> </Grid> <HierarchicalDataTemplate.ItemTemplate> <HierarchicalDataTemplate ItemsSource="{Binding Path=Children, Mode=OneTime}"> <!--<DataTemplate>--> <Grid > <Grid.ColumnDefinitions> <ColumnDefinition Width="Auto"/> <ColumnDefinition Width="Auto"/> <ColumnDefinition Width="*"/> </Grid.ColumnDefinitions> <CheckBox VerticalAlignment="Center" IsChecked="{Binding IsVisible}"/> <ContentPresenter Grid.Column="1" Content="{Binding LayerRepresentation, Mode=OneWay}" /> <TextBlock Margin="0,1,0,1" Text="{Binding Path=Alias, Mode=OneWay}" Grid.Column="2"> <ToolTipService.ToolTip> <TextBlock Text="{Binding Description}" TextWrapping="Wrap"/> </ToolTipService.ToolTip> </TextBlock> </Grid> <!--</DataTemplate>--> </HierarchicalDataTemplate> </HierarchicalDataTemplate.ItemTemplate> </HierarchicalDataTemplate> </TreeView.ItemTemplate> <TreeView.ContextMenu> <ContextMenu> <MenuItem Name="miRemove" Header="Remove" Command="{Binding ElementName=root, Path=RemoveItemCmd, diagnostics:PresentationTraceSources.TraceLevel=High}"> <MenuItem.Icon> <Image Source="../images/16x16/Delete.png"/> </MenuItem.Icon> </MenuItem> <MenuItem Header="Properties" Command="{Binding ElementName=root, Path=GetItemPropertiesCmd}"/> </ContextMenu> </TreeView.ContextMenu> </TreeView> </UserControl> Code behind for this UserControl has two ICommand properties with names: RemoveItemCmd and GetItemPropertiesCmd. However, I get System.Windows.Data Error: 4 : Cannot find source for binding with reference 'ElementName=root'. BindingExpression:Path=RemoveItemCmd; DataItem=null; target element is 'MenuItem' (Name='miRemove'); target property is 'Command' (type 'ICommand') System.Windows.Data Error: 4 : Cannot find source for binding with reference 'ElementName=root'. BindingExpression:Path=GetItemPropertiesCmd; DataItem=null; target element is 'MenuItem' (Name=''); target property is 'Command' (type 'ICommand') when UserControl is constructed. Why is this and how do I resolve?

    Read the article

  • Trying to get a better understanding of SelectedValuePath and IsSynchronizedWithCurrentItem

    - by rasx
    The following XAML produces a run-time Binding error when I click on an item in the ListBox: <Window xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:sys="clr-namespace:System;assembly=mscorlib" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" x:Class="WpfApplication1.MainWindow" x:Name="Window" Title="MainWindow" Width="640" Height="480"> <Window.Resources> <x:Array x:Key="strings" Type="{x:Type sys:String}"> <sys:String>one</sys:String> <sys:String>two</sys:String> <sys:String>three</sys:String> <sys:String>four</sys:String> </x:Array> </Window.Resources> <Grid> <ListBox DataContext="{StaticResource strings}" IsSynchronizedWithCurrentItem="True" ItemsSource="{Binding}" SelectedValuePath="{Binding /Length}"> <ListBox.ItemTemplate> <DataTemplate> <Grid> <Grid.Resources> <Style TargetType="{x:Type Label}"> <Setter Property="Background" Value="Yellow"/> <Setter Property="Margin" Value="0,0,4,0"/> <Setter Property="Padding" Value="0"/> </Style> </Grid.Resources> <Grid.ColumnDefinitions> <ColumnDefinition/> <ColumnDefinition/> </Grid.ColumnDefinitions> <Grid.RowDefinitions> <RowDefinition/> <RowDefinition/> </Grid.RowDefinitions> <!-- Row 0 --> <Label Grid.Column="0" Grid.Row="0">String:</Label> <TextBlock Grid.Column="1" Grid.Row="0" Text="{Binding}"/> <!-- Row 1 --> <Label Grid.Column="0" Grid.Row="1">Length:</Label> <TextBlock Grid.Column="1" Grid.Row="1" Text="{Binding Length, Mode=Default}"/> </Grid> </DataTemplate> </ListBox.ItemTemplate> </ListBox> </Grid> </Window> This is the run-time Binding error message: System.Windows.Data Error: 39 : BindingExpression path error: '3' property not found on 'object' ''String' (HashCode=1191344027)'. BindingExpression:Path=3; DataItem='String' (HashCode=1191344027); target element is 'ListBox' (Name=''); target property is 'NoTarget' (type 'Object') I would like the selected value of the ListBox to be the Length of the selected String object. What is wrong with my SelectedValuePath Binding syntax? Are there any related issues with IsSynchronizedWithCurrentItem?

    Read the article

  • F# WPF Form &ndash; the basics

    - by MarkPearl
    I was listening to Dot Net Rocks show #560 about F# and during the podcast Richard Campbell brought up a good point with regards to F# and a GUI. In essence what I understood his point to be was that until one could write an end to end application in F#, it would be a hard sell to developers to take it on. In part I agree with him, while I am beginning to really enjoy learning F#, I can’t but help feel that I would be a lot further into the language if I could do my Windows Forms like I do in C# or VB.NET for the simple reason that in “playing” applications I spend the majority of the time in the UI layer… So I have been keeping my eye out for some examples of creating a WPF form in a F# project and came across Tim’s F# Twitter Stream Sample, which had exactly this…. of course he actually had a bit more than a basic form… but it was enough for me to scrap the insides and glean what I needed. So today I am going to make just the very basic WPF form with all the goodness of a XAML window. Getting Started First thing we need to do is create a new solution with a blank F# application project – I have made mine called FSharpWPF. Once you have the project created you will need to change the project type from a Console Application to a Windows Application. You do this by right clicking on the project file and going to its properties… Once that is done you will need to add the appropriate references. You do this by right clicking on the References in the Solution Explorer and clicking “Add Reference'”. You should add the appropriate .Net references below for WPF & XAMl to work. Once these references are added you then need to add your XAML file to the project. You can do this by adding a new item to the project of type xml and simply changing the file extension from xml to xaml. Once the xaml file has been added to the project you will need to add valid window XAML. Example of a very basic xaml file is shown below… <Window xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Title="F# WPF WPF Form" Height="350" Width="525"> <Grid> </Grid> </Window> Once your xaml file is done… you need to set the build action of the xaml file from “None” to “Resource” as depicted in the picture below. If you do not set this you will get an IOException error when running the completed project with a message along the lines of “Cannot locate resource ‘window.xaml’ You then need to tie everything up by putting the correct F# code in the Program.fs to load the xaml window. In the Program.fs put the following code… module Program open System open System.Collections.ObjectModel open System.IO open System.Windows open System.Windows.Controls open System.Windows.Markup [<STAThread>] [<EntryPoint>] let main(_) = let w = Application.LoadComponent(new System.Uri("/FSharpWPF;component/Window.xaml", System.UriKind.Relative)) :?> Window (new Application()).Run(w) Once all this is done you should be able to build and run your project. What you have done is created a WPF based window inside a FSharp project. It should look something like below…   Nothing to exciting, but sufficient to illustrate the very basic WPF form in F#. Hopefully in future posts I will build on this to expose button events etc.

    Read the article

  • [WPF] Custom TabItem in TabControl

    - by Simon
    I've created CustomTabItem which inherits from TabItem and i'd like to use it while binding ObservableCollection in TabControl <TabControl ItemsSource="{Binding MyObservableCollection}"/> It should like this in XAML, but i do not know how change default type of the output item created by TabControl while binding. I've tried to create converter, but it has to do something like this inside convertin method: List<CustomTabItem> resultList = new List<CustomTabItem>(); And iterate through my input ObservableCollection, create my CustomTab based on item from collection and add it to resultList... I'd like to avoid it, bacause while creating CustomTabItem i'm creating complex View and it takes a while, so i don't want to create it always when something change in binded collection. My class extends typical TabItem and i'd like to use this class in TabControl instead of TabItem. <TabControl.ItemContainerStyle> <Style TargetType="{x:Type local:CustomTabItem}"> <Setter Property="MyProperty" Value="{Binding xxx}"/> </Style> </TabControl.ItemContainerStyle> Code above generates error that Style cannot be applied to TabItem. My main purpose is to use in XAML my own CustomTabItem and bind properties... Just like above... I've also tried to use <TabControl.ItemTemplate/> <TabControl.ContentTemaplte/> But they are just styles for TabItem, so i'll still be missing my properties wchich i added in my custom class.

    Read the article

< Previous Page | 14 15 16 17 18 19 20 21 22 23 24 25  | Next Page >