Search Results

Search found 11705 results on 469 pages for 'wpf layout'.

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

  • WPF binding and pointers

    - by Eran
    hey guys, I have a WPF application that contains windows with few user controls and Coordinator object. the window and all its user controls pointing to an object, which instace is in the Coordinator, by thier DataContext. the problem is that I want to change this object (e.g. create new object()) in the Coordinator but I want all the dataContexts to point to the new object. I tried to send the object by ref to the window constructor but it didn't help. any idea about how can I rewrite the memory location that all pointers are pointing to? (I don't want to repalce the properties in object since its a lot of work nor to use a middle object that points to the replaced object) Thanks Eran

    Read the article

  • how to bind to the results of a query in WPF

    - by randyc
    I have a query that hits a service and returns the results back to me as an indexed collection static void QueryActivities() { QueryClient qc = new QueryClient("BasicHttpBinding_IQuery"); QueryFilter filter = new QueryFilter(); filter.CallForService = false; var result = qc.GetFilteredActivityIndex(filter); result.Clone(); //inserted this just to test return in debug mode } WHen this is executed I get a return of 5 records ( actually five rows of data with multiple values per each row. id, type, date, address etc). I would like to bind this return to a gridview within a WPF application. Is there a way to refernce and bind to result variable or do I need to create a new collection and then add the return of result to the new collection? thank you

    Read the article

  • Binding a slider value on the height of its thumb in WPF

    - by sofri
    Hi, I have a databinding problem in WPF. I would like to "customise" a slider in a way that the thumb grows when you move the slider to the right and the thumb shrinks when you move the slider to the left. So I edited the template for the slider and changed the look of the slider so the slider looks like I want it to. But now I have to bind the height of the thumb to the value of the slider but I do not know how that works. I did some simple data binding things but I cannot figure out how I can bind this "thumb height" that's inside of my slider's template to the slider's value that's inside the User Control where my slider is in. So how can I do it?

    Read the article

  • WPF: Aligning the base line of a Label and its TextBox

    - by Heinzi
    Let's say I have a simple TextBox next to a Label: <StackPanel> <StackPanel Orientation="Horizontal"> <Label Margin="3">MyLabel</Label> <TextBox Margin="3" Width="100">MyText</TextBox> </StackPanel> ... </StackPanel> This yields the following result: As you can see, the base lines of MyLabel and MyText are not aligned, which looks ugly. Of course, I could start playing around with the margins until they match up, but since this is such a common requirement I'm sure that WPF provides a much easier and more elegant solution, which I just haven't found yet...

    Read the article

  • WPF, animate over container boundaries

    - by ImIan
    Hi, I'm learning WPF and have a specific goal. Imagine you have a grid (3 rows by 3 columns), and a control, say a simple blue rectangle fills the middle cell. When I click on the cell I want the square to rotate smoothly through 180 degrees. The specific issue I have at the moment is; as the rectangle rotates, it won't change its dimensions, so it will extend beyond the boundary of the cell. I don't want it to clip, i want it to appear on top, partially obscuring surrounding cells. The second part of this is, if there is one cell that fills the entire window, and I click on the blue rectangle in that cell, can I make the rectangle rotate and extend beyond the sides of the form? If that doesn't make sense, please ask. I'm finding it hard to google because I don't know the exact terms I should be using. Thank you

    Read the article

  • WPF - Make two controls the same size

    - by John Michaels
    Is there any way to make two controls that are in different containers the same size in WPF? For example, suppose you have two textboxes: textbox1 and textbox2. Textbox1 is in a grid and its size can grow and shrink when the user resizes the window. Textbox2 is in another part of the window and I need it to always have the same size as textbox1. Is there any way to do this? Keep in mind SharedSizeGroup will not work because the textboxes are in different containers. Also, I've tried binding textbox2's height property to textbox1 and that doesn't seem to work either. Finally, I tried catching textbox1's SizeChanged event, but its Height property is always NaN for some reason.

    Read the article

  • WPF TreeView binding to a simple object

    - by esse
    I have a simple object as such: public class Info { public string Name {get; set;} public int Count {get; set;} public DateTime TimeStamp {get; set;} } I want to bind a collection of these objects to a WPF TreeView and have the properties on the Info objects show up as sub TreeViewItems, like so: Item 1 Name: Bill Count: 3 TimeStamp: 12/05/2010 09:06:00 AM Item 2 Name: Chris Count: 22 TimeStamp: 11/05/2010 11:34:00 AM Item 3 Name: Toby Count: 1 TimeStamp: 09/05/2010 05:55:00 PM How can I achieve this through XAML?

    Read the article

  • Splitting up/merging windows in WPF

    - by drasto
    I'm new to WPF but I need to implement following functionality: I have a window that contains one Grid (might be changed to stack panel or something else). In that Grid I have 2 columns, each of them contains another Grid. Lets call them gridFirst and gridSecond. There is also GridSplitter in first column allowing to resize the columns. I want to provide a button that will allow to separate gridFirst from this window and display it "as it is" in another window. How do I do that? It would be nice if the new window had a same menu as the original window without me having to copy-paste (that not a good coding practise) all its code to the new window. Thanks for answers

    Read the article

  • Wrapping WPF UserControl inside VisualStudio Item Template

    - by karthik84
    I am currently started working on a project which will allow users to design reports inside visual studio. Previously, for my similar Winforms App, I had extended the IComponent (Component Class) and wrote our VS Like designer kind of custom control which will allow users to drag drop controls from the visual studio toolbox and then I export it as a VisualStudio C#&VB ItemTemplate. Now I am trying to recreate the same control using WPF considering its power, extensiblity. Could anyone shed some lights on this, on what would be the most preferable way of doing this ? Thanks in advance.

    Read the article

  • adding row dyanamicaly to gridview in WPF

    - by user572914
    Please help me with the following code,I want to add a row inputted by user to a gridview. I am able to add a row but its empty!!Please help.it worked in windows forms but its not working with WPF. private void button1_Click(object sender, RoutedEventArgs e) { GetGridView(); } private void GetGridView() { string[] row0 = {textBox1.Text,"Beatles" }; dataGrid1.Items.Add(row0); dataGrid1.Columns[0].DisplayIndex = 0; dataGrid1.Columns[1].DisplayIndex = 1; } ////////////// sure,here it is

    Read the article

  • Switching the layout in Orchard CMS

    - by Bertrand Le Roy
    The UI composition in Orchard is extremely flexible, thanks in no small part to the usage of dynamic Clay shapes. Every notable UI construct in Orchard is built as a shape that other parts of the system can then party on and modify any way they want. Case in point today: modifying the layout (which is a shape) on the fly to provide custom page structures for different parts of the site. This might actually end up being built-in Orchard 1.0 but for the moment it’s not in there. Plus, it’s quite interesting to see how it’s done. We are going to build a little extension that allows for specialized layouts in addition to the default layout.cshtml that Orchard understands out of the box. The extension will add the possibility to add the module name (or, in MVC terms, area name) to the template name, or module and controller names, or module, controller and action names. For example, the home page is served by the HomePage module, so with this extension you’ll be able to add an optional layout-homepage.cshtml file to your theme to specialize the look of the home page while leaving all other pages using the regular layout.cshtml. I decided to implement this sample as a theme with code. This way, the new overrides are only enabled as the theme is activated, which makes a lot of sense as this is going to be where you’ll be creating those additional layouts. The first thing I did was to create my own theme, derived from the default TheThemeMachine with this command: codegen theme CustomLayoutMachine /CreateProject:true /IncludeInSolution:true /BasedOn:TheThemeMachine .csharpcode, .csharpcode pre { font-size: 12px; color: black; font-family: consolas, "Courier New", courier, monospace; background-color: #ffffff; /*white-space: pre;*/ } .csharpcode pre { margin: 0em; } .csharpcode .rem { color: #008000; } .csharpcode .kwrd { color: #0000ff; } .csharpcode .str { color: #006080; } .csharpcode .op { color: #0000c0; } .csharpcode .preproc { color: #cc6633; } .csharpcode .asp { background-color: #ffff00; } .csharpcode .html { color: #800000; } .csharpcode .attr { color: #ff0000; } .csharpcode .alt { background-color: #f4f4f4; width: 100%; margin: 0em; } .csharpcode .lnum { color: #606060; } Once that was done, I worked around a known bug and moved the new project from the Modules solution folder into Themes (the code was already physically in the right place, this is just about Visual Studio editing). The CreateProject flag in the command-line created a project file for us in the theme’s folder. This is only necessary if you want to run code outside of views from that theme. The code that we want to add is the following LayoutFilter.cs: using System.Linq; using System.Web.Mvc; using System.Web.Routing; using Orchard; using Orchard.Mvc.Filters; namespace CustomLayoutMachine.Filters { public class LayoutFilter : FilterProvider, IResultFilter { private readonly IWorkContextAccessor _wca; public LayoutFilter(IWorkContextAccessor wca) { _wca = wca; } public void OnResultExecuting(ResultExecutingContext filterContext) { var workContext = _wca.GetContext(); var routeValues = filterContext.RouteData.Values; workContext.Layout.Metadata.Alternates.Add( BuildShapeName(routeValues, "area")); workContext.Layout.Metadata.Alternates.Add( BuildShapeName(routeValues, "area", "controller")); workContext.Layout.Metadata.Alternates.Add( BuildShapeName(routeValues, "area", "controller", "action")); } public void OnResultExecuted(ResultExecutedContext filterContext) { } private static string BuildShapeName( RouteValueDictionary values, params string[] names) { return "Layout__" + string.Join("__", names.Select(s => ((string)values[s] ?? "").Replace(".", "_"))); } } } This filter is intercepting ResultExecuting, which is going to provide a context object out of which we can extract the route data. We are also injecting an IWorkContextAccessor dependency that will give us access to the current Layout object, so that we can add alternate shape names to its metadata. We are adding three possible shape names to the default, with different combinations of area, controller and action names. For example, a request to a blog post is going to be routed to the “Orchard.Blogs” module’s “BlogPost” controller’s “Item” action. Our filters will then add the following shape names to the default “Layout”: Layout__Orchard_Blogs Layout__Orchard_Blogs__BlogPost Layout__Orchard_Blogs__BlogPost__Item Those template names get mapped into the following file names by the system (assuming the Razor view engine): Layout-Orchard_Blogs.cshtml Layout-Orchard_Blogs-BlogPost.cshtml Layout-Orchard_Blogs-BlogPost-Item.cshtml This works for any module/controller/action of course, but in the sample I created Layout-HomePage.cshtml (a specific layout for the home page), Layout-Orchard_Blogs.cshtml (a layout for all the blog views) and Layout-Orchard_Blogs-BlogPost-Item.cshtml (a layout that is specific to blog posts). Of course, this is just an example, and this kind of dynamic extension of shapes that you didn’t even create in the first place is highly encouraged in Orchard. You don’t have to do it from a filter, we only did it this way because that was a good place where we could get the context that we needed. And of course, you can base your alternate shape names on something completely different from route values if you want. For example, you might want to create your own part that modifies the layout for a specific content item, or you might want to do it based on the raw URL (like it’s done in widget rules) or who knows what crazy custom rule. The point of all this is to show that extending or modifying shapes is easy, and the layout just happens to be a shape. In other words, you can do whatever you want. Ain’t that nice? The custom theme can be found here: Orchard.Theme.CustomLayoutMachine.1.0.nupkg Many thanks to Louis, who showed me how to do this.

    Read the article

  • Binding Image.Source to String in WPF ?

    - by Mohammad
    I have below XAML code : <Window x:Class="WpfApplication1.Window1" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" DataContext="{Binding RelativeSource={RelativeSource Self}}" WindowStartupLocation="CenterScreen" Title="Window1" Height="300" Width="300"> <Grid> <Image x:Name="TestImage" Source="{Binding Path=ImageSource}" /> </Grid> </Window> Also, there is a method that makes an Image from a Base64 string : Image Base64StringToImage(string base64ImageString) { try { byte[] b; b = Convert.FromBase64String(base64ImageString); MemoryStream ms = new System.IO.MemoryStream(b); System.Drawing.Image img = System.Drawing.Image.FromStream(ms); ////////////////////////////////////////////// //convert System.Drawing.Image to WPF image System.Drawing.Bitmap bmp = new System.Drawing.Bitmap(img); IntPtr hBitmap = bmp.GetHbitmap(); System.Windows.Media.ImageSource imageSource = System.Windows.Interop.Imaging.CreateBitmapSourceFromHBitmap(hBitmap, IntPtr.Zero, Int32Rect.Empty, BitmapSizeOptions.FromEmptyOptions()); Image wpfImage = new Image(); wpfImage.Source = imageSource; wpfImage.Width = wpfImage.Height = 16; ////////////////////////////////////////////// return wpfImage; } catch { Image img1 = new Image(); img1.Source = new BitmapImage(new Uri(@"/passwordManager;component/images/TreeView/empty-bookmark.png", UriKind.Relative)); img1.Width = img1.Height = 16; return img1; } } Now, I'm gonna bind TestImage to the output of Base64StringToImage method. I've used the following way : public string ImageSource { get; set; } ImageSource = Base64StringToImage("iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAMAAAAoLQ9TAAAABGdBTUEAAK/INwWK6QAAABl0RVh0U29mdHdhcmUAQWRvYmUgSW1hZ2VSZWFkeXHJZTwAAABjUExURXK45////6fT8PX6/bTZ8onE643F7Pf7/pDH7PP5/dns+b7e9MPh9Xq86NHo947G7Hm76NTp+PL4/bHY8ojD67rc85bK7b3e9MTh9dLo97vd8/D3/Hy96Xe76Nfr+H+/6f///1bvXooAAAAhdFJOU///////////////////////////////////////////AJ/B0CEAAACHSURBVHjaXI/ZFoMgEEMzLCqg1q37Yv//KxvAlh7zMuQeyAS8d8I2z8PT/AMDShWQfCYJHL0FmlcXSQTGi7NNLSMwR2BQaXE1IfAguPFx5UQmeqwEHSfviz7w0BIMyU86khBDZ8DLfWHOGPJahe66MKe/fIupXKst1VXxW/VgT/3utz99BBgA4P0So6hyl+QAAAAASUVORK5CYIII").Source.ToString(); but nothing happen. How can I fix it ? BTW, I'm dead sure that the base64 string is correct

    Read the article

  • Need help understanding WPF MeasureOverride and ArrangeOverride infinity and 0 sizes

    - by Scott Bilas
    I'm trying to build a simple panel that contains one child and will snap it to nearest grid sizes. I'm having a hard time figuring out how to do this by overriding MeasureOverride and ArrangeOverride. Here's what I'm after: I want my panel to tell its owner that (a) it wants to be as large as possible, then (b) when it finds out what that size is, it will size itself and its child UIElement according to the nearest smaller snap point. So if we're snapping to 10's, and I can be in a region no bigger than 192x184, the panel will tell its parent container "my actual size is going to be 190x180". That way anything bordering my control will be able to align to its edges, as opposed to the potential space. When I put my panel inside of a Grid, I get either 0 or PositiveInfinity (I forget) for the incoming size in the overrides, but what I need to know is "how big can my space actually get?" not infinities.. Part of the problem I think is what WPF considers magic values of PositiveInfinity and 0 for size. I need a way to say, via MeasureOverride "I can be as big as you will allow me" and in ArrangeOverride to actually size to the snapped size. Or am I going about this the completely wrong way? Measuring and arranging looks very complicated, just from wandering around a little in the code for the standard panels in Reflector.

    Read the article

  • Automatic linebreak in WPF label

    - by Vlad
    Dear all, is it possible for a WPF Label to split itself automatically into several lines? In my following example, the text is cropped at the right. <Window x:Class="..." xmlns="..." xmlns:x="..." Height="300" Width="300"> <Grid> <Label> `_Twas brillig, and the slithy toves did gyre and gimble in the wabe: all mimsy were the borogoves, and the mome raths outgrabe.</Label> </Grid> </Window> Am I doing something wrong? Taking other controls is unfortunately not a good option, since I need support of access keys. Replacing the Label with a TextBlock (having TextWrapping="Wrap"), and adjusting its control template to recognize access keys would be perhaps a solution, but isn't it an overkill? Edit: having a non-standard style for label will break skinning, so I would like to avoid it if possible.

    Read the article

  • WPF Datagrid set the column values only when the row is left

    - by Noam
    Hello I have a simple class. When I use it in winforms binding, whenever I change a value of a cell and leave the cell, the property immediately get changed. Using WPF Datagrid, whenever i change a value of a cell, the property gets set only after I leave the row. That is problematic for me. What am I doing wrong? Here is my code: public class MyClass : IEditableObject, INotifyPropertyChanged { string _name, _lastName; public string Name { get { return _name; } set { _name = value; _lastName = value + " xxx"; OnPropertyChanged("LastName"); MessageBox.Show("Test"); } } private void OnPropertyChanged(string p) { var x = new PropertyChangedEventArgs(p); if (PropertyChanged != null) PropertyChanged(this, x); } public string LastName { get { return _lastName; } set { _lastName = value; } } public void BeginEdit() { } public void CancelEdit() { } public void EndEdit() { } public event PropertyChangedEventHandler PropertyChanged; } public class myBindingList : BindingList<MyClass> { public myBindingList() { AllowNew = true; Add(new MyClass { Name = "noam" }); Add(new MyClass { Name = "yael" }); } }

    Read the article

  • WPF: Change the style of a ViewBox depending upon the amount of data

    - by Brett Rigby
    Hi there, I have a WPF app that has a ViewBox to display the items in my collection, diplaying a 2-column grid for my results. What I'd like to do is, depending on the number of items in my collection, change the number of columns. E.g if there are < 10 items in the list, then show them in just 1 column; If there are 10 items in my list, then show them in 2 columns; If there are 20 items in my list, then show 3 columns. Here's what I have at present: <Viewbox> <ItemsControl ItemsSource="{Binding myCollection}" Style="{DynamicResource myStyle}" /> </Viewbox> Here's what myStyle currently defines: <Style x:Key="myStyle" TargetType="{x:Type ItemsControl}"> <Setter Property=ItemsControl.ItemsPanel"> <Setter.Value> <ItemsPanelTemplate> <UniformGrid Columns="2" /> </ItemsPanelTemplate> </Setter.Value> </Setter> </Style> How can I make this code work to the above requirement? Thanks.

    Read the article

  • WPF MVVM Chart change axes

    - by c0uchm0nster
    I'm new to WPF and MVVM. I'm struggling to determine the best way to change the view of a chart. That is, initially a chart might have the axes: X - ID, Y - Length, and then after the user changes the view (either via lisbox, radiobutton, etc) the chart would display the information: X - Length, Y - ID, and after a third change by the user it might display new content: X - ID, Y - Quality. My initial thought was that the best way to do this would be to change the bindings themselves. But I don't know how tell a control in XAML to bind using a Binding object in the ViewModel, or whether it's safe to change that binding in runtime? Then I thought maybe I could just have a generic Model that has members X and Y and populate them as needed in the viewmodel? My last thought was that I could have 3 different chart controls and just hide and show them as appropriate. What is the CORRECT/SUGGESTED way to do this in the MVVM pattern? Any code examples would be greatly appreciated. Thanks

    Read the article

  • WPF data validation is overriding theme on the interface

    - by black sensei
    Hello! Good People I built a WPF application and manage to get the validation working thanks to posts on stackoverflow.The only probblem i'm having is that it's overriding the theme i'm using. example the theme makes the textboxes look like a round rectangle but after setting the binding it look like the default textboxes. here is my code : <Button.Style> <Style TargetType="{x:Type Button}"> <Setter Property="IsEnabled" Value="false" /> <Style.Triggers> <!-- Require the controls to be valid in order to press OK --> <MultiDataTrigger> <MultiDataTrigger.Conditions> <Condition Binding="{Binding ElementName=txtEmail, Path=(Validation.HasError)}" Value="false" /> </MultiDataTrigger.Conditions> <Setter Property="IsEnabled" Value="true" /> </MultiDataTrigger> </Style.Triggers> </Style> </Button.Style> code behind is : //Form loaded event code txtEmail.GetBindingExpression(TextBox.TextProperty).UpdateSource(); I've tried to look into the theme file but i was quickly lost.i thought i could use that file like a web css file.Now i've disabled the data binding because of that.Is there any work around for this? thanks for reading this

    Read the article

  • WPF Databinding problem

    - by costin
    Hi, I'm new to WPF and I have some difficulties when I'm trying to populate a ListView with a list of custom objects. internal class ApplicationCode { public int Code { get; set; } public IEnumerable<string> InstrumentCodes { get; set; } } I have a list of ApplicationCode which I set to ItemsSource to a ListView. I need to display the ApplicationCode.Code as a string and for the rest of the columns a check box which can be checked/unchecked depending if the column name is contained in the InstrumentCodes collection. In order to set the check box I use a converter on databinding: <DataTemplate x:Key="InstrumentCodeTemplate"> <CheckBox IsEnabled="False" IsChecked="{Binding Mode=OneTime, Converter={StaticResource InstrumentSelectionConverter}}" /> </DataTemplate> The problem I have is because I can't know which is the current column at the time of cell data binding and I can't set the ConverterParameter. public object Convert(object value, Type targetType, object parameter, CultureInfo culture) { ApplicationCode appCode = value as ApplicationCode; return appCode != null && appCode.InstrumentCodes.Contains(parameter.ToString()); } There is a way to find out the column index or name? Or there is another way to solve this problem?

    Read the article

  • WPF, C# - Making Intellisense/Autocomplete list, fastest way to filter list of strings

    - by user559548
    Hello everyone, I'm writing an Intellisense/Autocomplete like the one you find in Visual Studio. It's all fine up until when the list contains probably 2000+ items. I'm using a simple LINQ statement for doing the filtering: var filterCollection = from s in listCollection where s.FilterValue.IndexOf(currentWord, StringComparison.OrdinalIgnoreCase) >= 0 orderby s.FilterValue select s; I then assign this collection to a WPF Listbox's ItemSource, and that's the end of it, works fine. Noting that, the Listbox is also virtualised as well, so there will only be at most 7-8 visual elements in memory and in the visual tree. However the caveat right now is that, when the user types extremely fast in the richtextbox, and on every key up I execute the filtering + binding, there's this semi-race condition, or out of sync filtering, like the first key stroke's filtering could still be doing it's filtering or binding work, while the fourth key stroke is also doing the same. I know I could put in a delay before applying the filter, but I'm trying to achieve a seamless filtering much like the one in Visual Studio. I'm not sure where my problem exactly lies, so I'm also attributing it to IndexOf's string operation, or perhaps my list of string's could be optimised in some kind of index, that could speed up searching. Any suggestions of code samples are much welcomed. Thanks.

    Read the article

  • Using a WPF ListView as a DataGrid

    - by psheriff
    Many people like to view data in a grid format of rows and columns. WPF did not come with a data grid control that automatically creates rows and columns for you based on the object you pass it. However, the WPF Toolkit can be downloaded from CodePlex.com that does contain a DataGrid control. This DataGrid gives you the ability to pass it a DataTable or a Collection class and it will automatically figure out the columns or properties and create all the columns for you and display the data.The DataGrid control also supports editing and many other features that you might not always need. This means that the DataGrid does take a little more time to render the data. If you want to just display data (see Figure 1) in a grid format, then a ListView works quite well for this task. Of course, you will need to create the columns for the ListView, but with just a little generic code, you can create the columns on the fly just like the WPF Toolkit’s DataGrid. Figure 1: A List of Data using a ListView A Simple ListView ControlThe XAML below is what you would use to create the ListView shown in Figure 1. However, the problem with using XAML is you have to pre-define the columns. You cannot re-use this ListView except for “Product” data. <ListView x:Name="lstData"          ItemsSource="{Binding}">  <ListView.View>    <GridView>      <GridViewColumn Header="Product ID"                      Width="Auto"               DisplayMemberBinding="{Binding Path=ProductId}" />      <GridViewColumn Header="Product Name"                      Width="Auto"               DisplayMemberBinding="{Binding Path=ProductName}" />      <GridViewColumn Header="Price"                      Width="Auto"               DisplayMemberBinding="{Binding Path=Price}" />    </GridView>  </ListView.View></ListView> So, instead of creating the GridViewColumn’s in XAML, let’s learn to create them in code to create any amount of columns in a ListView. Create GridViewColumn’s From Data TableTo display multiple columns in a ListView control you need to set its View property to a GridView collection object. You add GridViewColumn objects to the GridView collection and assign the GridView to the View property. Each GridViewColumn object needs to be bound to a column or property name of the object that the ListView will be bound to. An ADO.NET DataTable object contains a collection of columns, and these columns have a ColumnName property which you use to bind to the GridViewColumn objects. Listing 1 shows a sample of reading and XML file into a DataSet object. After reading the data a GridView object is created. You can then loop through the DataTable columns collection and create a GridViewColumn object for each column in the DataTable. Notice the DisplayMemberBinding property is set to a new Binding to the ColumnName in the DataTable. C#private void FirstSample(){  // Read the data  DataSet ds = new DataSet();  ds.ReadXml(GetCurrentDirectory() + @"\Xml\Product.xml");    // Create the GridView  GridView gv = new GridView();   // Create the GridView Columns  foreach (DataColumn item in ds.Tables[0].Columns)  {    GridViewColumn gvc = new GridViewColumn();    gvc.DisplayMemberBinding = new Binding(item.ColumnName);    gvc.Header = item.ColumnName;    gvc.Width = Double.NaN;    gv.Columns.Add(gvc);  }   // Setup the GridView Columns  lstData.View = gv;  // Display the Data  lstData.DataContext = ds.Tables[0];} VB.NETPrivate Sub FirstSample()  ' Read the data  Dim ds As New DataSet()  ds.ReadXml(GetCurrentDirectory() & "\Xml\Product.xml")   ' Create the GridView  Dim gv As New GridView()   ' Create the GridView Columns  For Each item As DataColumn In ds.Tables(0).Columns    Dim gvc As New GridViewColumn()    gvc.DisplayMemberBinding = New Binding(item.ColumnName)    gvc.Header = item.ColumnName    gvc.Width = [Double].NaN    gv.Columns.Add(gvc)  Next   ' Setup the GridView Columns  lstData.View = gv  ' Display the Data  lstData.DataContext = ds.Tables(0)End SubListing 1: Loop through the DataTable columns collection to create GridViewColumn objects A Generic Method for Creating a GridViewInstead of having to write the code shown in Listing 1 for each ListView you wish to create, you can create a generic method that given any DataTable will return a GridView column collection. Listing 2 shows how you can simplify the code in Listing 1 by setting up a class called WPFListViewCommon and create a method called CreateGridViewColumns that returns your GridView. C#private void DataTableSample(){  // Read the data  DataSet ds = new DataSet();  ds.ReadXml(GetCurrentDirectory() + @"\Xml\Product.xml");   // Setup the GridView Columns  lstData.View =      WPFListViewCommon.CreateGridViewColumns(ds.Tables[0]);  lstData.DataContext = ds.Tables[0];} VB.NETPrivate Sub DataTableSample()  ' Read the data  Dim ds As New DataSet()  ds.ReadXml(GetCurrentDirectory() & "\Xml\Product.xml")   ' Setup the GridView Columns  lstData.View = _      WPFListViewCommon.CreateGridViewColumns(ds.Tables(0))  lstData.DataContext = ds.Tables(0)End SubListing 2: Call a generic method to create GridViewColumns. The CreateGridViewColumns MethodThe CreateGridViewColumns method will take a DataTable as a parameter and create a GridView object with a GridViewColumn object in its collection for each column in your DataTable. C#public static GridView CreateGridViewColumns(DataTable dt){  // Create the GridView  GridView gv = new GridView();  gv.AllowsColumnReorder = true;   // Create the GridView Columns  foreach (DataColumn item in dt.Columns)  {    GridViewColumn gvc = new GridViewColumn();    gvc.DisplayMemberBinding = new Binding(item.ColumnName);    gvc.Header = item.ColumnName;    gvc.Width = Double.NaN;    gv.Columns.Add(gvc);  }   return gv;} VB.NETPublic Shared Function CreateGridViewColumns _  (ByVal dt As DataTable) As GridView  ' Create the GridView  Dim gv As New GridView()  gv.AllowsColumnReorder = True   ' Create the GridView Columns  For Each item As DataColumn In dt.Columns    Dim gvc As New GridViewColumn()    gvc.DisplayMemberBinding = New Binding(item.ColumnName)    gvc.Header = item.ColumnName    gvc.Width = [Double].NaN    gv.Columns.Add(gvc)  Next   Return gvEnd FunctionListing 3: The CreateGridViewColumns method takes a DataTable and creates GridViewColumn objects in a GridView. By separating this method out into a class you can call this method anytime you want to create a ListView with a collection of columns from a DataTable. SummaryIn this blog you learned how to create a ListView that acts like a DataGrid. You are able to use a DataTable as both the source of the data, and for creating the columns for the ListView. In the next blog entry you will learn how to use the same technique, but for Collection classes. NOTE: You can download the complete sample code (in both VB and C#) at my website. http://www.pdsa.com/downloads. Choose Tips & Tricks, then "WPF ListView as a DataGrid" from the drop-down. Good Luck with your Coding,Paul Sheriff ** SPECIAL OFFER FOR MY BLOG READERS **Visit http://www.pdsa.com/Event/Blog for a free eBook on "Fundamentals of N-Tier".

    Read the article

  • Open Source WPF UML Design tool

    - by oazabir
    PlantUmlEditor is my new free open source UML designer project built using WPF and .NET 3.5. If you have used plantuml before, you know that you can quickly create sophisitcated UML diagrams without struggling with a designer. Especially those who use Visio to draw UML diagrams (God forbid!), you will be at heaven. This is a super fast way to get your diagrams up and ready for show. You can *write* UML diagrams in plain English, following a simple syntax and get diagrams generated on-the-fly. This editor really saves time designing UML diagrams. I have to produce quick diagrams to convey ideas quickly to Architects, Designers and Developers everyday. So, I use this tool to write some quick diagrams at the speed of coding, and the diagrams get generated on the fly. Instead of writing a long mail explaining some complex operation or some business process in English, I can quickly write it in the editor in almost plain English, and get a nice looking activity/sequence diagram generated instantly. Making major changes is also as easy as doing search-replace and copy-pasting blocks here and there. You don't get such agility in any conventional mouse-based UML designers. I have submited a full codeproject article to give you a detail walkthrough how I have built this. Please read this article and vote for me if you like it. PlantUML Editor: A fast and simple UML editor using WPF http://www.codeproject.com/KB/smart/plantumleditor.aspx You can download the project from here: http://code.google.com/p/plantumleditor/

    Read the article

  • Introducing Kiddo: A Ruby DSL for building simple WPF and Silverlight applications

    - by fdumlao
    Read the original article here... As a long time Ruby lover and deep rooted .NET supporter, I was probably more psyched than anyone I knew when IronRuby 1.0 was finally released. I immediately grabbed and started building some apps with it to see where the boundaries were going to lie between IronRuby and ruby.exe, and so far I've been pleasantly surprised by how many things just work as I'd expect. I then started to try out some of my favorite libs that I was sure would not work with IronRuby, and I wasn't surprised at all when _why's amazing Shoes library didn't work. Being somewhat familiar with Shoes (it's a great DSL for building simple UIs in Ruby) I felt it wouldn't be that difficult to port it over and as it turned out, someone else had already started the work. As cool as this was, I was never quite satisfied with good 'ol shoes. While it was quite complete, it lacked simple extensibility points, and although easy, it wasn't quite "kid friendly". At the same time on the .NET side of the fence, IronRuby could easily compile XAML to create WPF and Silverlight UIs, but trying to do it declaratively in plain Ruby was no fun at all. And so, the Shoes-inspired, WPF/Silverlight GUI DSL was born. (and it lives here: http://bitbucket.org/fdumlao/kiddo/src) Introducing Kiddo Tell you what. Let's start with a quick code example first. We'll build a useful app that we can use to quickly reverse strings whenever we need it. Read the complete article here...

    Read the article

  • How to structure an application that combines WCF and WPF

    - by CiaranG
    I'm in the process of learning how to use WCF (Windows Communication Foundation) to allow a client/server desktop application to communicate. The application's UI will be implemented using WPF, and we will probably use SQL Server for our database. What I'm struggling with, is understanding how to structure such an application. From what I've read, there are three components of a WCF application (which in the examples I've seen have existed as separate projects): A WCF service A WCF service host A WCF service client My question then, is - should these projects solely implement the functionality of sending/receiving data from the client/server? Would it make better sense this way? Would it make sense to create a separate WPF (Windows Presentation Foundation) project to implement the UI for the application? And so, when I need to send/receive data from the client/server, I could simply invoke the operations provided in the WCF projects that I have created? For anyone who has built similar applications previously, perhaps you could explain what worked best for you in terms of structuring your application? For example, if I create a user registration page. When the user clicks the 'Register' button, the client application will need to send the data to the server. In this case, could I just invoke the methods provided in the WCF projects to send the data? Also, what data structures worked best for you when sending/receiving data? My initial thought is sending/receiving XML containing the data. Is this an option that is easy to implement? I realise that answers to this question may well be a matter of opinion - unless there are specific best practices that I'm not aware of. Thank you

    Read the article

  • WPF ToggleButton changing image depending on state

    - by mack369
    I would like to use ToggleButton in following way: There are 5 different images and each of them should be displayed depending on current state: button disabled button enabled, unchecked button enabled, unchecked, pointed by mouse cursor button enabled, checked button enabled, checked, pointed by mouse cursor I've found a simple example with two images on http://social.msdn.microsoft.com/Forums/en-US/wpf/thread/28c36bd2-2ef7-4232-9976-2a0967140e32 , but how to change the image depending on "checked" property? The second question: how can I avoid creating different styles for each button in my application? I'm using about 20 different buttons and each of them has different set of icons. So far I'm using only one icon, below my code. Is it possible to have common code (style and template) and to define the source of images in section where I want to create button (like in section 3 of my code)? <ControlTemplate x:Key="ToggleButtonTemplate" TargetType="{x:Type ToggleButton}"> <Grid> <Border x:Name="ContentBorder" CornerRadius="4" BorderBrush="Transparent" BorderThickness="1" Background="{DynamicResource ButtonOff}"> <ContentPresenter SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" Margin="{TemplateBinding Padding}" VerticalAlignment="{TemplateBinding VerticalContentAlignment}" RecognizesAccessKey="True"/> </Border> </Grid> <ControlTemplate.Triggers> <Trigger Property="IsPressed" Value="true"> <Setter TargetName="ContentBorder" Property="Background" Value="{DynamicResource ButtonOn}"/> </Trigger> <Trigger Property="IsChecked" Value="true"> <Setter TargetName="ContentBorder" Property="Background" Value="{DynamicResource ButtonOn}"/> </Trigger> <Trigger Property="IsEnabled" Value="false"> <Setter TargetName="ContentBorder" Property="Background" Value="{DynamicResource ButtonDisabled}"/> <Setter Property="Foreground" Value="{DynamicResource BorderDisabled}"/> </Trigger> </ControlTemplate.Triggers> </ControlTemplate> <Style x:Key="ToggleButtonStyle" TargetType="{x:Type ToggleButton}"> <Setter Property="Width" Value="64" /> <Setter Property="Height" Value="64" /> <Setter Property="HorizontalContentAlignment" Value="Center"/> <Setter Property="VerticalContentAlignment" Value="Center"/> <Setter Property="Template" Value="{DynamicResource ToggleButtonTemplate}" /> </Style> <ToggleButton IsChecked="{Binding Path=IsLectorModeEnabled}" Command="{Binding CmdLector}" Style="{DynamicResource ToggleButtonStyle}"> <Image Source="{DynamicResource LectorImage}" HorizontalAlignment="Center" VerticalAlignment="Center" Stretch="None" /> </ToggleButton>

    Read the article

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