Search Results

Search found 9012 results on 361 pages for 'wpf binding'.

Page 2/361 | < Previous Page | 1 2 3 4 5 6 7 8 9 10 11 12  | Next Page >

  • Question on MVVM pattern on WPF ?

    - by Ashish Ashu
    I have a user control let say UC1 . This user control have viewmodel UC1_vm. In the usercontrol UC1 I have a canvas in which drawing curve logic is implemented. This drawing curve logic is based on the data points property in the view model ( UC1_vm). The data points property inside the view model change with different condition. The generation of data points is written in the View Model. I want to bind the data points property in the view model to the draw curve logic inside the User control (view). I want whenever the data point property is changed in the view model , the canvas calls the draw curve method. Can I set the set any property of canvas which when changed it calls the on paint logic auto matically? Please suggest me the approach of implementing this scenario!!

    Read the article

  • Books about Advanced WPF control building

    - by Carlo
    Hello. I'm really interested in learning really advanced features of WPF to learn how to create advanced controls, but apparently I'm running out of resources, and possibly, imagination. I have these 4 books: WPF Control Development Unleashed Experiences Pro WPF 2008 Presentation Professionals Programming WPF Chris Sells WPF in Action Visual Studio 2008 One finished, two other half way, the other one just started. I sort of expected more from the "WPF Control Development Unleashed" one. Anyway, do you know any more books about advanced WPF features, and control building? Or even about how WPF works internally. Let me know what are your favorite WPF books, maybe I've overlooked some of them. Thanks!

    Read the article

  • [WPF Datagrid] Binding to a List<>

    - by Tr?n Qu?c Bình
    I have a datagrid like this: <dg:DataGrid Name="dg" AutoGenerateColumns="False" CanUserDeleteRows="True"> <dg:DataGrid.Columns> <dg:DataGridTextColumn Header="Product Code" x:Name="columnProductCode" Binding="{Binding Path=Product.ProductCode}" IsReadOnly="True" ></dg:DataGridTextColumn> <dg:DataGridTextColumn Header="Product Name" x:Name="columnProductName" Binding="{Binding Path=Product.Name}" IsReadOnly="True" ></dg:DataGridTextColumn> <dg:DataGridTextColumn Header="ProductMeasure" x:Name="columnDonViTinh" Binding="{Binding Path=Product.Measure IsReadOnly="True"></dg:DataGridTextColumn> <dg:DataGridTextColumn Header="Quantity" x:Name="ColumnQuantity" Binding="{Binding Path=Quantity IsReadOnly="False"></dg:DataGridTextColumn> </dg:DataGrid.Columns> </dg:DataGrid> In the behind code, I have a struct like this: private struct ProductDetail { public TProduct Product { get; set ; } // TProduct is a class provied by a web service public int Quantity { get; set; } } and a List like this: private IList<ProductDetail> bs = new List<ProductDetail>(); I had tried to fill data to "bs". And binding like this: this.dg.ItemsSource = this.bs; Everything is ok. I can insert a new row, delete row, but when I try to modified the column Quantity then click on the header of the datagrid (to resort) -- the Quantity column change to it is before. How can I fix this problem. Thanks advanced.

    Read the article

  • binding a command inside a listbox item to a property on the viewmodel parent

    - by gideon
    I've been working on this for about an hour and looked at all related SO questions. My problem is very simple: I have HomePageVieModel: HomePageVieModel +IList<NewsItem> AllNewsItems +ICommand OpenNews My markup: <Window DataContext="{Binding HomePageViewModel../> <ListBox ItemsSource="{Binding Path=AllNewsItems}"> <ListBox.ItemTemplate> <DataTemplate> <StackPanel> <TextBlock> <Hyperlink Command="{Binding Path=OpenNews}"> <TextBlock Text="{Binding Path=NewsContent}" /> </Hyperlink> </TextBlock> </StackPanel> </DataTemplate> </ListBox.ItemTemplate> The list shows fine with all the items, but for the life of me whatever I try for the Command won't work: <Hyperlink Command="{Binding Path=OpenNewsItem, RelativeSource={RelativeSource AncestorType=vm:HomePageViewModel, AncestorLevel=1}}"> <Hyperlink Command="{Binding Path=OpenNewsItem, RelativeSource={RelativeSource AncestorType=vm:HomePageViewModel,**Mode=FindAncestor}**}"> <Hyperlink Command="{Binding Path=OpenNewsItem, RelativeSource={RelativeSource AncestorType=vm:HomePageViewModel,**Mode=TemplatedParent}**}"> I just always get : System.Windows.Data Error: 4 : Cannot find source for binding with reference ..... Update I am setting my ViewModel like this? Didn't think this would matter: <Window.DataContext> <Binding Path="HomePage" Source="{StaticResource Locator}"/> </Window.DataContext> I use the ViewModelLocator class from the MVVMLight toolkit which does the magic.

    Read the article

  • Windows Presentation Foundation 4.5 Cookbook Review

    - by Ricardo Peres
    As promised, here’s my review of Windows Presentation Foundation 4.5 Cookbook, that Packt Publishing kindly made available to me. It is an introductory book, targeted at WPF newcomers or users with few experience, following the typical recipes or cookbook style. Like all Packt Publishing books on development, each recipe comes with sample code that is self-sufficient for understanding the concepts it tries to illustrate. It starts on chapter 1 by introducing the most important concepts, the XAML language itself, what can be declared in XAML and how to do it, what are dependency and attached properties as well as markup extensions and events, which should give readers a most required introduction to how WPF works and how to do basic stuff. It moves on to resources on chapter 2, which also makes since, since it’s such an important concept in WPF. Next, chapter 3, come the panels used for laying controls on the screen, all of the out of the box panels are described with typical use cases. Controls come next in chapter 4; the difference between elements and controls is introduced, as well as content controls, headered controls and items controls, and all standard controls are introduced. The book shows how to change the way they look by using templates. The next chapter, 5, talks about top level windows and the WPF application object: how to access startup arguments, how to set the main window, using standard dialogs and there’s even a sample on how to have a irregularly-shaped window. This is one of the most important concepts in WPF: data binding, which is the theme for the following chapter, 6. All common scenarios are introduced, the binding modes, directions, triggers, etc. It talks about the INotifyPropertyChanged interface and how to use it for notifying data binding subscribers of changes in data sources. Data templates and selectors are also covered, as are value converters and data triggers. Examples include master-detail and sorting, grouping and filtering collections and binding trees and grids. Last it covers validation rules and error templates. Chapter 7 talks about the current trend in WPF development, the Model View View-Model (MVVM) framework. This is a well known pattern for connecting things interface to actions, and it is explained competently. A typical implementation is presented which also presents the command pattern used throughout WPF. A complete application using MVVM is presented from start to finish, including typical features such as undo. Style and layout is covered on chapter 8. Why/how to use styles, applying them automatically,  using the many types of triggers to change styles automatically, using Expression Blend behaviors and templates are all covered. Next chapter, 9, is about graphics and animations programming. It explains how to create shapes, transform common UI elements, apply special effects and perform simple animations. The following chapter, 10, is about creating custom controls, either by deriving from UserControl or from an existing control or framework element class, applying custom templates for changing the way the control looks. One useful example is a custom layout panel that arranges its children along a circumference. The final chapter, 11, is about multi-threading programming and how one can integrate it with WPF. Includes how to invoke methods and properties on WPF classes from threads other than the main UI, using background tasks and timers and even using the new C# 5.0 asynchronous operations. It’s an interesting book, like I said, mostly for newcomers. It provides a competent introduction to WPF, with examples that cover the most common scenarios and also give directions to more complex ones. I recommend it to everyone wishing to learn WPF.

    Read the article

  • How does one bind to a List<DataRow> collection in WPF XAML?

    - by Elan
    Using a DataTable or DataView, one can specify the binding in XAML for example as follows: <Image Source="{Binding Thumbnail}" /> In my case I have created a List collection of DataRow objects and the above is not working. This is my data source: List<DataRow> I could of course convert the List< to a DataTable, but I am curious if there was a way to specify the binding in XAML to access the "Thumbnail" column within the DataRow that is stored in a List< collection. Elan

    Read the article

  • How does one bind to an List<DataRow> collection in WPF XAML?

    - by Elan
    Using a DataTable or DataView, one can specify the binding in XAML for example as follows: <Image Source="{Binding Thumbnail}" /> In my case I have created a List collection of DataRow objects and the above is not working. This is my data source: List<DataRow> I could of course convert the List< to a DataTable, but I am curious if there was a way to specify the binding in XAML to access the "Thumbnail" column within the DataRow that is stored in a List< collection. Elan

    Read the article

  • WPF ComboBox Binding breaks when using ControlTemplate

    - by Mitch
    I have a WPF ComboBox that has been working fine until I recently created a ControlTemplate for it to enable me to change the color of the DropDown arrow. The ComboBox still works correctly except the Bound Text value now just shows the name of the Business Object rather than the bound value. I guess that binding like Text="{Binding Path=CaseDateRange}" no longer works when using a ControlTemplate, yet the ItemsSource binding on the dropdown seems to still work fine. Can anyone offer some help with how I need to change my binding when using a ControlTemplate. The code for the ControlTemplate and ComboBox is as follows <ControlTemplate x:Key="ComboBoxControlTemplate1" TargetType="{x:Type ComboBox}"> <Grid x:Name="MainGrid" SnapsToDevicePixels="True"> <Grid.ColumnDefinitions> <ColumnDefinition Width="*"/> <ColumnDefinition MinWidth="{DynamicResource {x:Static SystemParameters.VerticalScrollBarWidthKey}}" Width="0"/> </Grid.ColumnDefinitions> <Popup x:Name="PART_Popup" AllowsTransparency="True" Grid.ColumnSpan="2" IsOpen="{Binding IsDropDownOpen, RelativeSource={RelativeSource TemplatedParent}}" Margin="1" PopupAnimation="{DynamicResource {x:Static SystemParameters.ComboBoxPopupAnimationKey}}" Placement="Bottom" OpacityMask="#FF2A3D64"> <Microsoft_Windows_Themes:SystemDropShadowChrome x:Name="Shdw" Color="Transparent" MaxHeight="{TemplateBinding MaxDropDownHeight}" MinWidth="{Binding ActualWidth, ElementName=MainGrid}"> <Border x:Name="DropDownBorder" BorderBrush="White" BorderThickness="1" CornerRadius="3" Background="{DynamicResource DialogDarkBlue}"> <ScrollViewer x:Name="DropDownScrollViewer" > <Grid RenderOptions.ClearTypeHint="Enabled"> <Canvas HorizontalAlignment="Left" Height="0" VerticalAlignment="Top" Width="0"> <Rectangle x:Name="OpaqueRect" Fill="{Binding Background, ElementName=DropDownBorder}" Height="{Binding ActualHeight, ElementName=DropDownBorder}" Width="{Binding ActualWidth, ElementName=DropDownBorder}"/> </Canvas> <ItemsPresenter x:Name="ItemsPresenter" KeyboardNavigation.DirectionalNavigation="Contained" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"/> </Grid> </ScrollViewer> </Border> </Microsoft_Windows_Themes:SystemDropShadowChrome> </Popup> <ToggleButton BorderBrush="{TemplateBinding BorderBrush}" Background="{TemplateBinding Background}" Grid.ColumnSpan="2" IsChecked="{Binding IsDropDownOpen, Mode=TwoWay, RelativeSource={RelativeSource TemplatedParent}}" Foreground="White"> <ToggleButton.Style> <Style TargetType="{x:Type ToggleButton}"> <Setter Property="OverridesDefaultStyle" Value="True"/> <Setter Property="IsTabStop" Value="False"/> <Setter Property="Focusable" Value="False"/> <Setter Property="ClickMode" Value="Press"/> <Setter Property="Template"> <Setter.Value> <ControlTemplate TargetType="{x:Type ToggleButton}"> <Microsoft_Windows_Themes:ButtonChrome x:Name="Chrome" BorderBrush="{TemplateBinding BorderBrush}" Background="{TemplateBinding Background}" RenderMouseOver="{TemplateBinding IsMouseOver}" RenderPressed="{TemplateBinding IsPressed}" SnapsToDevicePixels="True"> <Grid HorizontalAlignment="Right" Width="{DynamicResource {x:Static SystemParameters.VerticalScrollBarWidthKey}}"> <Path x:Name="Arrow" Data="M0,0L3.5,4 7,0z" Fill="White" HorizontalAlignment="Center" Margin="3,1,0,0" VerticalAlignment="Center"/> </Grid> </Microsoft_Windows_Themes:ButtonChrome> <ControlTemplate.Triggers> <Trigger Property="IsChecked" Value="True"> <Setter Property="RenderPressed" TargetName="Chrome" Value="True"/> </Trigger> <Trigger Property="IsEnabled" Value="False"> <Setter Property="Fill" TargetName="Arrow" Value="#FFAFAFAF"/> </Trigger> </ControlTemplate.Triggers> </ControlTemplate> </Setter.Value> </Setter> </Style> </ToggleButton.Style> </ToggleButton> <ContentPresenter ContentTemplate="{TemplateBinding SelectionBoxItemTemplate}" Content="{TemplateBinding SelectionBoxItem}" ContentStringFormat="{TemplateBinding SelectionBoxItemStringFormat}" HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" IsHitTestVisible="False" Margin="{TemplateBinding Padding}" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" VerticalAlignment="{TemplateBinding VerticalContentAlignment}"/> </Grid> <ControlTemplate.Triggers> <Trigger Property="HasDropShadow" SourceName="PART_Popup" Value="True"> <Setter Property="Margin" TargetName="Shdw" Value="0,0,5,5"/> <Setter Property="Color" TargetName="Shdw" Value="#71000000"/> </Trigger> <Trigger Property="HasItems" Value="False"> <Setter Property="Height" TargetName="DropDownBorder" Value="95"/> </Trigger> <Trigger Property="IsEnabled" Value="False"> <Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.GrayTextBrushKey}}"/> <Setter Property="Background" Value="#FFF4F4F4"/> </Trigger> <Trigger Property="IsGrouping" Value="True"> <Setter Property="ScrollViewer.CanContentScroll" Value="False"/> </Trigger> <Trigger Property="CanContentScroll" SourceName="DropDownScrollViewer" Value="False"> <Setter Property="Canvas.Top" TargetName="OpaqueRect" Value="{Binding VerticalOffset, ElementName=DropDownScrollViewer}"/> <Setter Property="Canvas.Left" TargetName="OpaqueRect" Value="{Binding HorizontalOffset, ElementName=DropDownScrollViewer}"/> </Trigger> </ControlTemplate.Triggers> </ControlTemplate> And the ComboBox is <ComboBox x:Name="cboSelectedCase" Text="{Binding Path=CaseDateRange}" DisplayMemberPath="CaseDateRange" SelectedValuePath="CaseID" Template="{DynamicResource ComboBoxControlTemplate1}" />

    Read the article

  • binding a command inside a listbox item to a property on the viewmodel parent

    - by giddy
    I've been working on this for about an hour and looked at all related SO questions. My problem is very simple: I have HomePageVieModel: HomePageVieModel +IList<NewsItem> AllNewsItems +ICommand OpenNewsItem My markup: <Window DataContext="{Binding HomePageViewModel../> <ListBox ItemsSource="{Binding Path=AllNewsItems}"> <ListBox.ItemTemplate> <DataTemplate> <StackPanel> <TextBlock> <Hyperlink Command="{Binding Path=OpenNews}"> <TextBlock Text="{Binding Path=NewsContent}" /> </Hyperlink> </TextBlock> </StackPanel> </DataTemplate> </ListBox.ItemTemplate> The list shows fine with all the items, but for the life of me whatever I try for the Command won't work: <Hyperlink Command="{Binding Path=OpenNewsItem, RelativeSource={RelativeSource AncestorType=vm:HomePageViewModel, AncestorLevel=1}}"> <Hyperlink Command="{Binding Path=OpenNewsItem, RelativeSource={RelativeSource AncestorType=vm:HomePageViewModel,**Mode=FindAncestor}**}"> <Hyperlink Command="{Binding Path=OpenNewsItem, RelativeSource={RelativeSource AncestorType=vm:HomePageViewModel,**Mode=TemplatedParent}**}"> I just always get : System.Windows.Data Error: 4 : Cannot find source for binding with reference .....

    Read the article

  • OneWay binding throws "TwoWay binding is invalid on Read only property"

    - by Binary Worrier
    This binding <tk:DataGridTextColumn Binding="{Binding Path=Id, Mode=OneWay}" Header="Sale No." Width="1*" /> Gives this error A TwoWay or OneWayToSource binding cannot work on the read-only property 'Id' of type . . . The "Id" property is indeed readonly, I thought though that Mode=OneWay would be sufficient. I'm tired and I know I'm missing something obvious so I'll apologies now for asking a really dumb question. Thanks BW

    Read the article

  • WPF: How to data bind an object to an element and apply a data template through code?

    - by Boris
    I have created a class LeagueMatch. public class LeagueMatch { public string Home { get { return home; } set { home = value; } } public string Visitor { get { return visitor; } set { visitor = value; } } private string home; private string visitor; public LeagueMatch() { } } Next, I have defined a datatemplate resource for LeagueMatch objects in XAML: <DataTemplate x:Key="MatchTemplate" DataType="{x:Type entities:LeagueMatch}"> <Grid Name="MatchGrid" Width="140" Height="50" Margin="5"> <Grid.RowDefinitions> <RowDefinition Height="*" /> <RowDefinition Height="*" /> <RowDefinition Height="*" /> </Grid.RowDefinitions> <TextBlock Grid.Row="0" Text="{Binding Home}" /> <TextBlock Grid.Row="1" Text="- vs -" /> <TextBlock Grid.Row="2" Text="{Binding Visitor}" /> </Grid> </DataTemplate> In the XAML code-behind, I want to create a ContentPresenter object and to set it's data binding to a previously initialized LeagueMatch object and apply the defined data template. How is that supposed to be done? Thanks.

    Read the article

  • WPF Toolkit Charting and IndependentValueBinding, IndependentValuePath

    - by Joel Barsotti
    So I'm having a problem with the charting engine from the WPF toolkit. We haven't moved our data to a proper object model, so the ItemSource is backed with a DataView. First attempt <chartingToolkit:ScatterSeries x:Name="TargetSeries" DataPointStyle="{StaticResource TargetStyle}" ItemsSource="{Binding Path=TargetSeriesData}" IndependentValueBinding="{Binding Path=TargetSeries_X}" DependentValueBinding="{Binding Path=TargetSeries_X}" /> This crashes because, I believe, it thinks the bindings are the values to plot or some sort of mismatch. Second attempt <chartingToolkit:ScatterSeries x:Name="TargetSeries" DataPointStyle="{StaticResource TargetStyle}" ItemsSource="{Binding Path=TargetSeriesData}" IndependentValuePath="{Binding Path=TargetSeries_X}" DependentValuePath="{Binding Path=TargetSeries_X}" /> This crashes during the init step becaue the Path properties aren't backed with dependency properties and therefore cannot be bound. Third attempt <chartingToolkit:ScatterSeries x:Name="TargetSeries" DataPointStyle="{StaticResource TargetStyle}" ItemsSource="{Binding Path=TargetSeriesData}" IndependentValuePath="targetFooXColumnName" DependentValuePath="targetFooYColumnName" /> Now this works! But I wanted to use the binding so I can switch from using the targetFooXColumnName to the targetFooBarXColumnName. So this solution will cause a whole lot of hacky looking code to switch the Path's manually. Anyway to fix this? Can I use some sort of convertor to get the Binding properties to correctly pull the data from the columns in the DataView? Thanks, Joel

    Read the article

  • ItemsControl ItemTemplate Binding

    - by Wonko the Sane
    Hi All, In WPF4.0, I have a class that contains other class types as properties (combining multiple data types for display). Something like: public partial class Owner { public string OwnerName { get; set; } public int OwnerId { get; set; } } partial class ForDisplay { public Owner OwnerData { get; set; } public int Credit { get; set; } } In my window, I have an ItemsControl with the following (clipped for clarity): <ItemsControl ItemsSource={Binding}> <ItemsControl.ItemTemplate> <DataTemplate> <local:MyDisplayControl OwnerName={Binding OwnerData.OwnerName} Credit={Binding Credit} /> </DataTemplate> </ItemsControl.ItemTemplate> </ItemsControl> I then get a collection of display information from the data layer, and set the DataContext of the ItemsControl to this collection. The "Credit" property gets displayed correctly, but the OwnerName property does not. Instead, I get a binding error: Error 40: BindingExpression path error: 'OwnerName' property not found on 'object' ''ForDisplay' (HashCode=449124874)'. BindingExpression:Path=OwnerName; DataItem='ForDisplay' (HashCode=449124874); target element is 'TextBlock' (Name=txtOwnerName'); target property is 'Text' (type 'String') I don't understand why this is attempting to look for the OwnerName property in the ForDisplay class, rather than in the Owner class from the ForDisplay OwnerData property. Edit It appears that it has something to do with using the custom control. If I bind the same properties to a TextBlock, they work correctly. <ItemsControl ItemsSource={Binding}> <ItemsControl.ItemTemplate> <DataTemplate> <StackPanel> <local:MyDisplayControl OwnerName={Binding OwnerData.OwnerName} Credit={Binding Credit} /> <TextBlock Text="{Binding OwnerData.OwnerName}" /> <TextBlock Text="{Binding Credit}" /> </StackPanel> </DataTemplate> </ItemsControl.ItemTemplate> </ItemsControl> Thanks, wTs

    Read the article

  • Unset/Change Binding in WPF

    - by captcalamares
    How can I unset the binding applied to an object so that I can apply another binding to it from a different location? Suppose I have two data templates binded to the same object reference. Data Template #1 is the default template to be loaded. I try to bind a button command to a Function1 from my DataContext class: <Button Content="Button 1" CommandParameter="{Binding }" Command="{Binding DataContext.Function1, RelativeSource={RelativeSource AncestorType={x:Type Window}}}"/> This actually works and the function gets binded. However, when I try to load Data Template # 2 to the same object (while trying to bind another button command to a different function (Function2) from my DataContext class): <Button Content="Button 2" CommandParameter="{Binding }" Command="{Binding DataContext.Function2, RelativeSource={RelativeSource AncestorType={x:Type Window}}}" /> It doesn't work and the first binding is still the one executed. Is there a workaround to this? EDIT (for better problem context): I defined my templates in my Window.Resources: <Window.Resources> <DataTemplate DataType="{x:Type local:ViewModel1}"> <local:View1 /> </DataTemplate> <DataTemplate DataType="{x:Type local:ViewModel2}"> <local:View2 /> </DataTemplate> </Window.Resources> The View1.xaml and the View2.xaml contain the button definitions that I described above (I want them to command the control of my process flow). ViewModel1 and ViewModel2 are my ViewModels that implement the interface IPageViewModel which is the type of my variable CurrentPageViewModel. In my XAML, I binded ContentControl to the variable CurrentPageViewModel: <ContentControl Content="{Binding CurrentPageViewModel}" HorizontalAlignment="Center"/> In my .CS, I have a list defined as List<IPageViewModel> PageViewModels, which I use to contain the instances of my two View Models: PageViewModels.Add(new ViewModel1()); PageViewModels.Add(new ViewModel2()); // Set starting page CurrentPageViewModel = PageViewModels[0]; When I try to change my CurrentPageViewModel to the other view model, this is when I want the new binding to work. Unfortunately, it doesn't. Am I doing things the right way?

    Read the article

  • WPF: Bind DataGrid to List<String>

    - by Sam
    Funny, how sometimes the simple things bite me in the behind. I can bind a DataGrid nicely to a Collection of some arbitrary class, using a DataGridTextColumn like this: <DataGridTextColumn Header="Name" Binding="{Binding Name}"/> Now I want to bind a DataGrid to a simple Collection. So since there is no property "Name" or something like that to bind to, how do I write the binding: <DataGridTextColumn Header="Name" Binding="{Binding ???}"/> String has no Property "Value" or something like that. And if I just write {Binding } I'll end up with a one-way-binding, unable to write changes back to the Collection. Thinking about it, I think it is not possible to bind to a collection, so I do need to wrap my string into a class? Or is there a way?

    Read the article

  • Wpf binding to a function

    - by carlopenid
    I've a created a simple scrollviewer (pnlDayScroller) and want to have a separate horizontal scrollbar (associated scroller) to do the horizontal scrolling. All works with the below code accept I need to bind the visibility of the associated scroller. I can't simply bind this to the visibility property of the horizontal template part of the scroll viewer as I've set this to be always hidden. The only way I can think to do this is to bind the visibility of the associated scroller to a function such that If associatedScroller.scrollableWidth > 0 then associatedScroller.visibility = visibility.visible else associatedScroller.visibility = visibility.collapsed end if Is this possible to do and if so how do I do it? Private Sub pnlDayScroller_Loaded(ByVal sender As System.Object, ByVal e As System.Windows.RoutedEventArgs) Handles pnlDayScroller.Loaded Dim binViewport, binMax, binMin, binSChange, binLChange As Binding Dim horizontalScrollBar As Primitives.ScrollBar = CType(pnlDayScroller.Template.FindName("PART_HorizontalScrollBar", pnlDayScroller), Primitives.ScrollBar) binViewport = New Binding("ViewportSize") binViewport.Mode = BindingMode.OneWay binViewport.Source = horizontalScrollBar associatedScroller.SetBinding(Primitives.ScrollBar.ViewportSizeProperty, binViewport) binMax = New Binding("Maximum") binMax.Mode = BindingMode.OneWay binMax.Source = horizontalScrollBar associatedScroller.SetBinding(Primitives.ScrollBar.MaximumProperty, binMax) binMin = New Binding("Minimum") binMin.Mode = BindingMode.OneWay binMin.Source = horizontalScrollBar associatedScroller.SetBinding(Primitives.ScrollBar.MinimumProperty, binMin) binSChange = New Binding("SmallChange") binSChange.Mode = BindingMode.OneWay binSChange.Source = horizontalScrollBar associatedScroller.SetBinding(Primitives.ScrollBar.SmallChangeProperty, binSChange) binLChange = New Binding("LargeChange") binLChange.Mode = BindingMode.OneWay binLChange.Source = horizontalScrollBar associatedScroller.SetBinding(Primitives.ScrollBar.LargeChangeProperty, binLChange) End Sub Private Sub associatedScroller_Scroll(ByVal sender As System.Object, ByVal e As System.Windows.RoutedPropertyChangedEventArgs(Of Double)) Handles associatedScroller.ValueChanged pnlDayScroller.ScrollToHorizontalOffset(e.NewValue) end sub FOLLOW UP (thanks to JustABill) : I've add this code into the pnlDayScroller sub above (I've discovered scrollableWidth is a property of scrollviewer not scrollbar, but the maximum property gives a result I can use instead) binVisibility = New Binding("Maximum") binVisibility.Mode = BindingMode.OneWay binVisibility.Source = horizontalScrollBar binVisibility.Converter = New ScrollableConverter associatedScroller.SetBinding(Primitives.ScrollBar.VisibilityProperty, binVisibility) and I've created this class Public Class ScrollableConverter Implements IValueConverter Public Function Convert(ByVal value As Object, ByVal targetType As Type, ByVal parameter As Object, ByVal culture As System.Globalization.CultureInfo) As Object Implements IValueConverter.Convert Dim dblMaximum As Double If targetType IsNot GetType(Visibility) Then Throw New InvalidOperationException("The target must be a visibility") Else dblMaximum = CType(value, Double) Debug.WriteLine("Value of double is " & dblMaximum) If dblMaximum > 0 Then Return Visibility.Visible Else Return Visibility.Collapsed End If End If End Function Public Function ConvertBack(ByVal value As Object, ByVal targetType As Type, ByVal parameter As Object, ByVal culture As System.Globalization.CultureInfo) As Object Implements IValueConverter.ConvertBack Throw New NotSupportedException() End Function End Class And the problem is resolved.

    Read the article

  • WPF binding to a boolean on a control

    - by Jose
    I'm wondering if someone has a simple succinct solution to binding to a dependency property that needs to be the converse of the property. Here's an example I have a textbox that is disabled based on a property in the datacontext e.g.: <TextBox IsEnabled={Binding CanEdit} Text={Binding MyText}/> The requirement changes and I want to make it ReadOnly instead of disabled, so without changing my ViewModel I could do this: In the UserControl resources: <UserControl.Resources> <m:NotConverter x:Key="NotConverter"/> </UserControl.Resources> And then change the TextBox to: <TextBox IsReadOnly={Binding CanEdit,Converter={StaticResource NotConverter}} Text={Binding MyText}/> Which I personally think is EXTREMELY verbose I would love to be able to just do this(notice the !): <TextBox IsReadOnly={Binding !CanEdit} Text={Binding MyText}/> But alas, that is not an option that I know of. I can think of two options. Create an attached property IsNotReadOnly to FrameworkElement(?) and bind to that property If I change my ViewModel then I could add a property CanEdit and another CannotEdit which I would be kind of embarrassed of because I believe it adds an irrelevant property to a class, which I don't think is a good practice. The main reason for the question is that in my project the above isn't just for one control, so trying to keep my project as DRY as possible and readable I am throwing this out to anyone feeling my pain and has come up with a solution :)

    Read the article

  • Dependency Property WPF Grid

    - by developer
    Hi All, I want to Bind the textblock text in WPF datagrid to a dependency property. Somehow, nothing gets displayed, but when I use the same textblock binding outside the grid, everything works fine. Below is my code, <Window.Resources> <Style x:Key="cellCenterAlign" TargetType="{x:Type toolkit:DataGridCell}"> <Setter Property="Template"> <Setter.Value> <ControlTemplate TargetType="{x:Type toolkit:DataGridCell}"> <Grid Background="{TemplateBinding Background}"> <ContentPresenter HorizontalAlignment="Center" VerticalAlignment="Center"/> </Grid> </ControlTemplate> </Setter.Value> </Setter> </Style> <Style x:Key="ColumnHeaderStyle" TargetType="{x:Type toolkit:DataGridColumnHeader}"> <Setter Property="VerticalContentAlignment" Value="Center" /> <Setter Property="HorizontalContentAlignment" Value="Center"/> </Style> <ObjectDataProvider MethodName="GetValues" ObjectType="{x:Type sys:Enum}" x:Key="RoleValues"> <ObjectDataProvider.MethodParameters> <x:Type TypeName="domain:SubscriptionRole"/> </ObjectDataProvider.MethodParameters> </ObjectDataProvider> <DataTemplate x:Key="myTemplate"> <StackPanel> <TextBlock Text="{Binding Path=OtherSubs}"/> </StackPanel> </DataTemplate> </Window.Resources> <Grid> <Grid.RowDefinitions> <RowDefinition Height="220"/> <RowDefinition Height="Auto"/> </Grid.RowDefinitions> <StackPanel Grid.Row="0"> <toolkit:DataGrid Name="definitionGrid" Margin="0,10,0,0" AutoGenerateColumns="False" CanUserAddRows="False" CanUserDeleteRows="False" IsReadOnly="False" RowHeight="25" FontWeight="Normal" ItemsSource="{Binding programSubscription}" ColumnHeaderStyle="{DynamicResource ColumnHeaderStyle}" SelectionMode="Single" ScrollViewer.HorizontalScrollBarVisibility="Disabled" Width="450" ScrollViewer.VerticalScrollBarVisibility="Auto" Height="200"> <toolkit:DataGrid.Columns> <toolkit:DataGridTextColumn Header="Program" Width="80" Binding="{Binding Program.JobNum}" CellStyle="{StaticResource cellCenterAlign}" IsReadOnly="True"/> <toolkit:DataGridTemplateColumn Header="Role" Width="80" CellStyle="{StaticResource cellCenterAlign}"> <toolkit:DataGridTemplateColumn.CellTemplate> <DataTemplate> <ComboBox SelectedItem="{Binding Role}" ItemsSource="{Binding Source={StaticResource RoleValues}}" Width="70"> <ComboBox.Style> <Style> <Style.Triggers> <DataTrigger Binding="{Binding Path=Role}" Value="Owner"> <Setter Property="ComboBox.Focusable" Value="False"/> <Setter Property="ComboBox.IsEnabled" Value="False"/> <Setter Property="ComboBox.IsHitTestVisible" Value="False"/> </DataTrigger> </Style.Triggers> </Style> </ComboBox.Style> </ComboBox> </DataTemplate> </toolkit:DataGridTemplateColumn.CellTemplate> </toolkit:DataGridTemplateColumn> <toolkit:DataGridCheckBoxColumn Header="Email" Width="60" Binding="{Binding ReceivesEmail}" CellStyle="{StaticResource cellCenterAlign}"/> <!--<toolkit:DataGridTextColumn Header="Others" Width="220" Binding="{Binding programSubscription1.Subscriber.Username}" CellStyle="{StaticResource cellCenterAlign}" IsReadOnly="True"/>--> <toolkit:DataGridTemplateColumn Header="Others" Width="220" CellStyle="{StaticResource cellCenterAlign}" IsReadOnly="True"> <toolkit:DataGridTemplateColumn.CellTemplate> <DataTemplate> <TextBlock Text="{Binding Path=OtherSubs}"/> </DataTemplate> </toolkit:DataGridTemplateColumn.CellTemplate> </toolkit:DataGridTemplateColumn> </toolkit:DataGrid.Columns> </toolkit:DataGrid> <TextBlock Text="{Binding Path=OtherSubs}"/> </StackPanel> <Grid Grid.Row="1"> <Grid.ColumnDefinitions> <ColumnDefinition Width="200"/> <ColumnDefinition Width="*"/> </Grid.ColumnDefinitions> <StackPanel Grid.Column="0" HorizontalAlignment="Center" VerticalAlignment="Center"> <CheckBox Content="Show Only Active Programs" IsChecked="True" Margin="0,0,8,0"/> </StackPanel> <StackPanel Orientation="Horizontal" VerticalAlignment="Center" Grid.Column="1" HorizontalAlignment="Right"> <Button Content="Save" Height="23" Width="75" Margin="0,0,8,0" Click="Save_Click"/> <Button Content="Cancel" Height="23" Width="75" Margin="0,0,8,0" Click="Cancel_Click" /> </StackPanel> </Grid> </Grid> Code-Behind public partial class ProgramSubscriptions : Window { public static ObservableCollection programSubscription { get; set; } public string OtherSubs { get { return (string)GetValue(OtherSubsProperty); } set { SetValue(OtherSubsProperty, value); } } public static readonly DependencyProperty OtherSubsProperty = DependencyProperty.Register("OtherSubs", typeof(string), typeof(ProgramSubscriptions), new UIPropertyMetadata(string.Empty)); private string CurrentUsername = "test"; public ProgramSubscriptions() { InitializeComponent(); DataContext = this; LoadData(); } protected void LoadData() { programSubscription = new ObservableCollection<ProgramSubscriptionViewModel>(); if (res != null && res.TotalResults > 0) { List<ProgramSubscriptionViewModel> UserPrgList = new List<ProgramSubscriptionViewModel>(); //other.... List<ProgramSubscriptionViewModel> OtherPrgList = new List<ProgramSubscriptionViewModel>(); ArrayList myList = new ArrayList(); foreach (DomainObject obj in res.ResultSet) { ProgramSubscription prg = (ProgramSubscription)obj; if (prg.Subscriber.Username == CurrentUsername) { UserPrgList.Add(new ProgramSubscriptionViewModel(prg)); myList.Add(prg.Program.ID); } else OtherPrgList.Add(new ProgramSubscriptionViewModel(prg)); } for (int i = 0; i < UserPrgList.Count; i++) { ProgramSubscriptionViewModel item = UserPrgList[i]; programSubscription.Add(item); } //other.... for (int i = 0; i < OtherPrgList.Count; i++) { foreach (int y in myList) { ProgramSubscriptionViewModel otheritem = OtherPrgList[i]; if (y == otheritem.Program.ID) OtherSubs += otheritem.Subscriber.Username + ", "; } } } } } I posted the entire code. What exactly I want to do is in the datagridtemplatecolumn for others I want to display the usernames that are not in CurrentUsername, but they have the same program Id as the CurrentUsername. Please do let me know if there is another way that i can make this work, instead of using a dependencyproperty, althouht for testing I did put a textblock below datagrid, and it works perfectly fine.. Help!

    Read the article

  • Silverlight 3 Binding to the Current Item in a Collection

    - by rasx
    The Binding syntax, {Binding /}, works in WPF but does not work at all in Silverlight 3: <ContentControl Content="{Binding MyCollection}"> <ContentControl.ContentTemplate> <DataTemplate> <ContentControl Content="{Binding /}" /> </DataTemplate> </ContentControl.ContentTemplate> </ContentControl> What's the way to approach this in Silverlight?

    Read the article

  • SelectedItem in ListView binding

    - by Matt
    I'm new in wfp. In my sample application I'm using a ListView to display contents of property. I don't know how to bind SelectedItem in ListView to property and then bind to TextBlock. Window.xaml <Window x:Class="Exec.App" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Title="Main window" Height="446" Width="475" > <Grid> <ListView Name="ListViewPersonDetails" Margin="15,12,29,196" ItemsSource="{Binding Persons}" SelectedItem="{Binding CurrentSelectedPerson}"> <ListView.View> <GridView> <GridViewColumn Header="FirstName" DisplayMemberBinding="{Binding FstNamePerson}"/> <GridViewColumn Header="LastName" DisplayMemberBinding="{Binding SndNamePerson}"/> <GridViewColumn Header="Address" DisplayMemberBinding="{Binding AdressPerson}"/> </GridView> </ListView.View> </ListView> <TextBlock Height="23" Name="textFirstNameBlock" FontSize="12" Margin="97,240,155,144"> <Run Text="Name: " /> <Run Text="{Binding CurrentSelectedPerson.FstNamePerson}" FontWeight="Bold" /> </TextBlock> <TextBlock Height="23" Name="textLastNameBlock" FontSize="12" Margin="97,263,155,121"> <Run Text="Branch: " /> <Run Text="{Binding CurrentSelectedPerson.SndNamePerson}" FontWeight="Bold" /> </TextBlock> <TextBlock Height="23" Name="textAddressBlock" FontSize="12" Margin="0,281,155,103" HorizontalAlignment="Right" Width="138"> <Run Text="City: " /> <Run Text="{Binding CurrentSelectedPerson.AdressPerson}" FontWeight="Bold" /> </TextBlock> </Grid> </Window> MainWindow.xaml.cs Tman manager = new Tman(); private List<Person> persons; public List<Person> Persons { get { return this.persons; } set { if (value != null) { this.persons = value; this.NotifyPropertyChanged("Data"); } } } private Person currentSelectedPerson; public Person CurrentSelectedPerson { get { return currentSelectedPerson; } set { this.currentSelectedPerson = value; this.NotifyPropertyChanged("CurrentSelectedItem"); } } public event PropertyChangedEventHandler PropertyChanged; private void NotifyPropertyChanged(string propertyName) { var handler = this.PropertyChanged; if (handler != null) { handler(this, new PropertyChangedEventArgs(propertyName)); } } private void Window_Loaded(object sender, RoutedEventArgs e){ ListViewPersonDetails.ItemsSource= manager.GetPersons(); } Person.cs class Person { public string FirstName { get; set; } public string LastName { get; set; } public string Address { get; set; } } Thanks for any help.

    Read the article

  • Custom CheckBox in WPF DataGrid does not update binding

    - by Pakman
    In my Visual Studio 2010 WPF application, I have the following (simplified) style: <Style x:Key="MyStyle" TargetType="{x:Type CheckBox}"> <Setter Property="Background" Value="Blue" /> </Style> If I use it as the ElementStyle AND EditingElementStyle in my DataGridCheckBoxColumn: <DataGridCheckBoxColumn Binding="{Binding IsEnabled}" ElementStyle="{StaticResource MyStyle}" EditingElementStyle="{StaticResource MyStyle}" /> Then my binding, IsEnabled, does not toggle when I check/uncheck a row's checkbox. If I remove either ElementStyle, EditingElementStyle, or both, then the binding updates no problem. Why is this?! Also, I tried to work around the problem using the following code: <DataGridTemplateColumn> <DataGridTemplateColumn.CellTemplate> <DataTemplate> <CheckBox IsChecked="{Binding IsEnabled}" /> </DataTemplate> </DataGridTemplateColumn.CellTemplate> </DataGridTemplateColumn> However, the problem remains.

    Read the article

  • WPF Binding to DataRow Columns

    - by Trindaz
    Hi, I've taken some sample code from http://sweux.com/blogs/smoura/index.php/wpf/2009/06/15/wpf-toolkit-datagrid-part-iv-templatecolumns-and-row-grouping/ that provides grouping of data in a WPF DataGrid. I'm modifying the example to use a DataTable instead of a Collection of entities. My problem is in translating a binding declaration {Binding Parent.IsExpanded}, which works fine where Parent is a reference to an entity that has the IsExpanded attribute, to something that will work for my weakly typed DataTable, where Parent is the name of a column and references another DataRow in the same DataTable. I've tried declarations like {Binding Parent.Items[IsExpanded]} and {Binding Parent("IsExpanded")} but none of these seem to work. How can I create a binding to the IsExpanded column of the DataRow Parent in my DataTable? Thanks in advance, Dave

    Read the article

  • Shorter Binding expression with validation

    - by Andrii V
    Hi, I'm repeating same binding parameters for every textbox and they're quite long strings (which is not good for many reasons). And I'm wondering if there's a way to make them shorter? For instance all my controls on forms are using the following binding template: Text="{Binding SourceProperty, UpdateSourceTrigger=PropertyChanged, ValidatesOnExceptions=True, ValidatesOnDataErrors=True, NotifyOnValidationError=True}" I'd would like to have something shorter that ideally will take SourceProperty as parameter. Possbly like this: Text="{MyBinding SourceProperty}" or Text="{Binding SourceProperty, Params=MyParams}" One possible option would be to inherit from Binding and create new markup extension. Did someone tried this? Any other ideas how to make these repetetive bindings look better?

    Read the article

  • WPF - Correct Syntax for Using Coverter with Current Binding

    - by Andy T
    Hi, I have a collection of hex strings that represent colours and I am binding a combobox's ItemsSource to that collection. The combobox items are templated to have a filled rectangle with the relevant colour. I therefore need to use a converter to convert the hex value to a string. Easy enough. However, Blend is telling me that this syntax is incorrect in my XAML: Fill="{Binding, Converter={StaticResource StringToBrush}}" Apparently, I can't use a converter against plain old 'Binding'. Blend says that something like this is syntactically correct: Fill="{Binding Value, Converter={StaticResource StringToBrush}}" ...However that obviously doesn't work. I'm not quite au fait with binding syntax yet, so obviously I'm getting it wrong. Can anyone advise the correct syntax to achieve what I'm trying to do (convert my bound String using the coverter StringToBrush)? Thanks in advance! AT

    Read the article

  • Why doesn't my binding update whenever EditingElementStyle AND ElementStyle are set to a custom styl

    - by Pakman
    In my Visual Studio 2010 WPF application, I have the following (simplified) style: <Style x:Key="MyStyle" TargetType="{x:Type CheckBox}"> <Setter Property="Background" Value="Blue" /> </Style> If I use it as the ElementStyle AND EditingElementStyle in my DataGridCheckBoxColumn: <DataGridCheckBoxColumn Binding="{Binding IsEnabled}" ElementStyle="{StaticResource MyStyle}" EditingElementStyle="{StaticResource MyStyle}" /> Then my binding, IsEnabled, does not toggle when I check/uncheck a row's checkbox. If I remove either ElementStyle, EditingElementStyle, or both, then the binding updates no problem. Why is this?! Note: sometimes clicking around will produce an update to the binding (detected via debugging) - this is not the same as clicking another row to "commit" the value, though! Thanks!

    Read the article

< Previous Page | 1 2 3 4 5 6 7 8 9 10 11 12  | Next Page >