Search Results

Search found 64 results on 3 pages for 'datatrigger'.

Page 3/3 | < Previous Page | 1 2 3 

  • Changing colour of text in a textblock via a trigger

    - by Sike12
    Here is my Xaml <Window.Resources> <sampleData:MainWindow x:Key="DataSource"/> <DataTemplate x:Key="bobReferencer"> <TextBlock Text="{Binding Name}" > <TextBlock.Style> <Style TargetType="TextBlock"> <Style.Triggers> <DataTrigger Binding="{Binding HasErrors}" Value="true"> //what goes in here? </DataTrigger> </Style.Triggers> </Style> </TextBlock.Style> </TextBlock> </DataTemplate> </Window.Resources> Codebehind (the one xaml references) public class bob { public string Name { get; set; } public bool HasErrors { get; set; } Basically what i want to do is if the HasErrors is true then i want the Name to appear in Red via the trigger. But my xaml is not properly formed. Any suggestions on this? I also looked into this link but didn't help much. How can I change the Foreground color of a TextBlock with a Trigger?

    Read the article

  • Changing color of HighlighBrushKey in XAML

    - by phil
    Hi, I have the following problem. The background color in a ListView is set LightGreen or White, whether a boolflag is true or false. Example Screen Window1.xaml: <Window.Resources> <Style TargetType="{x:Type ListViewItem}"> <Style.Triggers> <DataTrigger Binding="{Binding Path=BoolFlag}" Value="True"> <Setter Property="Background" Value="LightGreen" /> </DataTrigger> </Style.Triggers> </Style> </Window.Resources> <StackPanel> <ListView ItemsSource="{Binding Path=Personen}" SelectionMode="Single" SelectionChanged="ListViewSelectionChanged"> <ListView.View> <GridView> <GridViewColumn DisplayMemberBinding="{Binding Path=Vorname}" Header="Vorname" /> <GridViewColumn DisplayMemberBinding="{Binding Path=Nachname}" Header="Nachname" /> <GridViewColumn DisplayMemberBinding="{Binding Path=Alter}" Header="Alter" /> <GridViewColumn DisplayMemberBinding="{Binding Path=BoolFlag}" Header="BoolFlag" /> </GridView> </ListView.View> </ListView> </StackPanel> Window1.xaml.cs: public partial class Window1 : Window { private IList<Person> _personen = new List<Person>(); public Window1() { _personen.Add(new Person { Vorname = "Max", Nachname = "Mustermann", Alter = 18, BoolFlag = false, }); _personen.Add(new Person { Vorname = "Karl", Nachname = "Mayer", Alter = 27, BoolFlag = true, }); _personen.Add(new Person { Vorname = "Josef", Nachname = "Huber", Alter = 38, BoolFlag = false, }); DataContext = this; InitializeComponent(); } public IList<Person> Personen { get { return _personen; } } private void ListViewSelectionChanged(object sender, SelectionChangedEventArgs e) { Person person = e.AddedItems[0] as Person; if (person != null) { if (person.BoolFlag) { this.Resources[SystemColors.HighlightBrushKey] = Brushes.Green; } else { this.Resources[SystemColors.HighlightBrushKey] = Brushes.RoyalBlue; } } } } Person.cs: public class Person { public string Vorname { get; set; } public string Nachname { get; set; } public int Alter { get; set; } public bool BoolFlag { get; set; } } Now I want to set the highlight color of the selected item, depending on the boolflag. In Code-Behind I do this with: private void ListViewSelectionChanged(object sender, SelectionChangedEventArgs e) { Person person = e.AddedItems[0] as Person; if (person != null) { if (person.BoolFlag) { this.Resources[SystemColors.HighlightBrushKey] = Brushes.Green; } else { this.Resources[SystemColors.HighlightBrushKey] = Brushes.RoyalBlue; } } } } This works fine, but now I want to define the code above in the XAML-file. With <SolidColorBrush x:Key="{x:Static SystemColors.HighlightBrushKey}" Color="Green" /> I can overwrite the default-value. However, it works, but the color is set to Green for all selected items. I have tried different ways to switch the color of HighlightBrushKey between Green and Blue in XAML, depending on the boolflag, but I didn't succeed. May you can help me and give me some examples?

    Read the article

  • Silverlight DataStateBehavior, initial value not used

    - by JimmySavile
    Hi, I am trying to use the Silverlight DataStateBehavior, it works fine in most cases where I click a button which sets say a 'Selected' Property in the view model to either false or true. The DataStateBehavior then tells the VisualStateManager to go to the relevant state. Like this: <Button...> <i:Interaction.Behaviors> <id:DataStateBehavior Binding="{Binding Selected}" Value="True" TrueState="SelectedVisualState" FalseState="DeselectedVisualState"/> </i:Interaction.Behaviors> </Button> The above works fine. What I am trying to do though is to get it to set the correct state when the application loads, if I were to set the 'Selected' property on the view model to true by default I wouldn't see any changes in the UI until I clicked the button to change the viewmodel property. I know there are several classes involved with the DataState stuff including: BindingListener.cs ConverterHelper.cs DataStateBehavior.cs DataStateSwitchBehavior.cs DataTrigger.cs Any clues would be good, Thanks

    Read the article

  • Wpf Listbox and Togglebutton

    - by Tan
    Hi iam using a listbox to show a list of items. in the listbox i ahve an togglebutton on every item. When i click on the toggle button the state of the togglebutton is pressed. But when i am scrolling down in the listbox and scolls up again. The togglebutton state is not pressed. How can i prevent this please help. Heres my itemtemplate <ListBox.ItemTemplate> <DataTemplate> <StackPanel Margin="0,3,0,0"> <Border BorderBrush="Black" BorderThickness="1,1,1,1"> <Border.Background> <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0" MappingMode="RelativeToBoundingBox"> <GradientStop Color="#FFECECEC" Offset="1"/> <GradientStop Color="#FFE8E8E8"/> <GradientStop Color="#FFBDBDBD" Offset="0.153"/> <GradientStop Color="#FFE8E8E8" Offset="0.904"/> </LinearGradientBrush> </Border.Background> <Border.Style> <Style> <Style.Triggers> <DataTrigger Binding="{Binding Path=IsSelected, RelativeSource={RelativeSource Mode=FindAncestor,AncestorType={x:Type ListBoxItem}}}" Value="True"> <Setter Property="Border.Height" Value="100"/> <Setter Property="Border.Background"> <Setter.Value> <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0" MappingMode="RelativeToBoundingBox"> <GradientStop Color="DarkGray" Offset="1"/> <GradientStop Color="#FFE8E8E8"/> <GradientStop Color="#FFBDBDBD" Offset="0.153"/> <GradientStop Color="DarkGray" Offset="0.904"/> </LinearGradientBrush> </Setter.Value> </Setter> </DataTrigger> </Style.Triggers> </Style> </Border.Style> <StackPanel Orientation="Horizontal" VerticalAlignment="Center"> <Grid> <Grid.ColumnDefinitions> <ColumnDefinition Width="500"/> <ColumnDefinition Width="100"/> <ColumnDefinition Width="55"/> </Grid.ColumnDefinitions> <!--Pick number--> <StackPanel Grid.Column="0" VerticalAlignment="Center" Orientation="Vertical"> <TextBlock Text="{Binding Path=FtgNamn}" FontWeight="Bold" FontSize="22pt" FontFamily="Calibri"/> <TextBlock Text="{Binding Path=LevsAttBeskr}" FontSize="18pt" FontFamily="Calibri"/> </StackPanel> <!--Pick Quantity--> <StackPanel Grid.Column="1" VerticalAlignment="Center"> <TextBlock Text="{Binding Path=Antal}" FontSize="44pt" FontFamily="Calibri"/> </StackPanel> <!-- Checkbox--> <StackPanel Grid.Column="2" VerticalAlignment="Center" HorizontalAlignment="Center"> <ToggleButton Name="Check" Width="40" Height="40" Click="Check_Click" Tag="{Binding Path=Plocklista}"> <ToggleButton.Style> <Style TargetType="ToggleButton"> <Setter Property="Template"> <Setter.Value> <ControlTemplate TargetType="{x:Type ToggleButton}"> <Border x:Name="InnerBorder" Background="White" BorderBrush="Black" BorderThickness="1"/> <ControlTemplate.Triggers> <Trigger Property="IsChecked" Value="True"> <Setter TargetName="InnerBorder" Property="Background"> <Setter.Value> <ImageBrush ImageSource="/Images/button_ok.png"/> </Setter.Value> </Setter> <Setter TargetName="InnerBorder" Property="BorderThickness" Value="0"/> </Trigger> </ControlTemplate.Triggers> </ControlTemplate> </Setter.Value> </Setter> </Style> </ToggleButton.Style> </ToggleButton> </StackPanel> </Grid> <Border BorderBrush="Darkgray" BorderThickness="0,0,1,0"> </Border> <TextBlock Width="100" Text="{Binding Path=Quantity}" FontSize="44pt" FontFamily="Calibri"/> <CheckBox Width="78"/> </StackPanel> </Border> </StackPanel> </DataTemplate>

    Read the article

  • Binding UserControl to a NULL DataContext

    - by user634981
    I have a UserControl and am binding its DataContext to an object. I also bind the IsEnabled property of the UserControl to a boolean property of that object eg: <my:MyUserControl DataContext="{Binding Items.SelectedItem}" IsEnabled="{Binding Path=IsEditable}"/> This works fine provided Items.SelectedItem is not null. However, if it is null (which can happen sometimes if the Items collection is empty), the IsEnabled binding does not get evaluated and is set to true, which is not the desired behaviour. I've tried using a MultiBinding but without success because I don't know if it's possible to bind to the DataContext. I've also tried using a DataTrigger, but again without success. Would somebody kindly point me in the right direction as to the correct way I should be doing this. Thanks!

    Read the article

  • Wpf Listbox and CheckBox

    - by Tan
    Hi iam using a listbox to show a list of items. in the listbox i ahve an togglebutton on every item. When i click on the toggle button the state of the togglebutton is pressed. But when i am scrolling down in the listbox and scolls up again. The togglebutton state is not pressed. How can i prevent this please help. Heres my itemtemplate <ListBox.ItemTemplate> <DataTemplate> <StackPanel Margin="0,3,0,0"> <Border BorderBrush="Black" BorderThickness="1,1,1,1"> <Border.Background> <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0" MappingMode="RelativeToBoundingBox"> <GradientStop Color="#FFECECEC" Offset="1"/> <GradientStop Color="#FFE8E8E8"/> <GradientStop Color="#FFBDBDBD" Offset="0.153"/> <GradientStop Color="#FFE8E8E8" Offset="0.904"/> </LinearGradientBrush> </Border.Background> <Border.Style> <Style> <Style.Triggers> <DataTrigger Binding="{Binding Path=IsSelected, RelativeSource={RelativeSource Mode=FindAncestor,AncestorType={x:Type ListBoxItem}}}" Value="True"> <Setter Property="Border.Height" Value="100"/> <Setter Property="Border.Background"> <Setter.Value> <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0" MappingMode="RelativeToBoundingBox"> <GradientStop Color="DarkGray" Offset="1"/> <GradientStop Color="#FFE8E8E8"/> <GradientStop Color="#FFBDBDBD" Offset="0.153"/> <GradientStop Color="DarkGray" Offset="0.904"/> </LinearGradientBrush> </Setter.Value> </Setter> </DataTrigger> </Style.Triggers> </Style> </Border.Style> <StackPanel Orientation="Horizontal" VerticalAlignment="Center"> <Grid> <Grid.ColumnDefinitions> <ColumnDefinition Width="500"/> <ColumnDefinition Width="100"/> <ColumnDefinition Width="55"/> </Grid.ColumnDefinitions> <!--Pick number--> <StackPanel Grid.Column="0" VerticalAlignment="Center" Orientation="Vertical"> <TextBlock Text="{Binding Path=FtgNamn}" FontWeight="Bold" FontSize="22pt" FontFamily="Calibri"/> <TextBlock Text="{Binding Path=LevsAttBeskr}" FontSize="18pt" FontFamily="Calibri"/> </StackPanel> <!--Pick Quantity--> <StackPanel Grid.Column="1" VerticalAlignment="Center"> <TextBlock Text="{Binding Path=Antal}" FontSize="44pt" FontFamily="Calibri"/> </StackPanel> <!-- Checkbox--> <StackPanel Grid.Column="2" VerticalAlignment="Center" HorizontalAlignment="Center"> <ToggleButton Name="Check" Width="40" Height="40" Click="Check_Click" Tag="{Binding Path=Plocklista}"> <ToggleButton.Style> <Style TargetType="ToggleButton"> <Setter Property="Template"> <Setter.Value> <ControlTemplate TargetType="{x:Type ToggleButton}"> <Border x:Name="InnerBorder" Background="White" BorderBrush="Black" BorderThickness="1"/> <ControlTemplate.Triggers> <Trigger Property="IsChecked" Value="True"> <Setter TargetName="InnerBorder" Property="Background"> <Setter.Value> <ImageBrush ImageSource="/Images/button_ok.png"/> </Setter.Value> </Setter> <Setter TargetName="InnerBorder" Property="BorderThickness" Value="0"/> </Trigger> </ControlTemplate.Triggers> </ControlTemplate> </Setter.Value> </Setter> </Style> </ToggleButton.Style> </ToggleButton> </StackPanel> </Grid> <Border BorderBrush="Darkgray" BorderThickness="0,0,1,0"> </Border> <TextBlock Width="100" Text="{Binding Path=Quantity}" FontSize="44pt" FontFamily="Calibri"/> <CheckBox Width="78"/> </StackPanel> </Border> </StackPanel> </DataTemplate>

    Read the article

  • WPF - hiding listbox items

    - by user553765
    Hi, I have a listbox where the itemtemplate is using a style. The styles specifies a border with a datatrigger setting the visibility of the border to collapsed depending on a property. This works fine except I can still see a very narrow line for each item, in the list, that is collapsed. I was hoping someone could help with how to set the visibility so that there are no visible traces as this is quite apparent when consecutive items have been collapsed. The datatemplate specifies an outer border with a dockpanel inside of this - there are then stackpanels docked to this. Any help is appreciated.

    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

  • MVVM/WPF: DataTemplate is not changed in Wizard

    - by msfanboy
    Hello, I wonder why my contentcontrol(headeredcontentcontrol) does not change the datatemplates when I press the previous/next button. While debugging everything seems ok means I jump forth and back the collection of wizardpages but always the first page is shown and its header text not the usercontrol is visible. What do I have forgotten? using System; using System.Collections.Generic; using System.Linq; using System.Text; using GalaSoft.MvvmLight.Command; using System.Collections.ObjectModel; using System.Diagnostics; using System.ComponentModel; namespace TBM.ViewModel { public class WizardMainViewModel { WizardPageViewModelBase _currentPage; ReadOnlyCollection _pages; RelayCommand _moveNextCommand; RelayCommand _movePreviousCommand; public WizardMainViewModel() { this.CurrentPage = this.Pages[0]; } public RelayCommand MoveNextCommand { get { return _moveNextCommand ?? (_moveNextCommand = new RelayCommand(() => this.MoveToNextPage(), () => this.CanMoveToNextPage)); } } public RelayCommand MovePreviousCommand { get { return _movePreviousCommand ?? (_movePreviousCommand = new RelayCommand( () => this.MoveToPreviousPage(), () => this.CanMoveToPreviousPage)); } } bool CanMoveToPreviousPage { get { return 0 < this.CurrentPageIndex; } } bool CanMoveToNextPage { get { return this.CurrentPage != null && this.CurrentPage.IsValid(); } } void MoveToPreviousPage() { this.CurrentPage = this.Pages[this.CurrentPageIndex - 1]; } void MoveToNextPage() { if (this.CurrentPageIndex < this.Pages.Count - 1) this.CurrentPage = this.Pages[this.CurrentPageIndex + 1]; } /// <summary> /// Returns the page ViewModel that the user is currently viewing. /// </summary> public WizardPageViewModelBase CurrentPage { get { return _currentPage; } private set { if (value == _currentPage) return; if (_currentPage != null) _currentPage.IsCurrentPage = false; _currentPage = value; if (_currentPage != null) _currentPage.IsCurrentPage = true; this.OnPropertyChanged("CurrentPage"); this.OnPropertyChanged("IsOnLastPage"); } } public bool IsOnLastPage { get { return this.CurrentPageIndex == this.Pages.Count - 1; } } /// <summary> /// Returns a read-only collection of all page ViewModels. /// </summary> public ReadOnlyCollection<WizardPageViewModelBase> Pages { get { return _pages ?? CreatePages(); } } ReadOnlyCollection<WizardPageViewModelBase> CreatePages() { WizardPageViewModelBase welcomePage = new WizardWelcomePageViewModel(); WizardPageViewModelBase schoolclassPage = new WizardSchoolclassSubjectPageViewModel(); WizardPageViewModelBase lessonPage = new WizardLessonTimesPageViewModel(); WizardPageViewModelBase timetablePage = new WizardTimeTablePageViewModel(); WizardPageViewModelBase finishPage = new WizardFinishPageViewModel(); var pages = new List<WizardPageViewModelBase>(); pages.Add(welcomePage); pages.Add(schoolclassPage); pages.Add(lessonPage); pages.Add(timetablePage); pages.Add(finishPage); return _pages = new ReadOnlyCollection<WizardPageViewModelBase>(pages); } int CurrentPageIndex { get { if (this.CurrentPage == null) { Debug.Fail("Why is the current page null?"); return -1; } return this.Pages.IndexOf(this.CurrentPage); } } public event PropertyChangedEventHandler PropertyChanged; void OnPropertyChanged(string propertyName) { PropertyChangedEventHandler handler = this.PropertyChanged; if (handler != null) handler(this, new PropertyChangedEventArgs(propertyName)); } } } <UserControl x:Class="TBM.View.WizardMainView" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:ViewModel="clr-namespace:TBM.ViewModel" xmlns:View="clr-namespace:TBM.View" mc:Ignorable="d" > <UserControl.Resources> <DataTemplate DataType="{x:Type ViewModel:WizardWelcomePageViewModel}"> <View:WizardWelcomePageView /> </DataTemplate> <DataTemplate DataType="{x:Type ViewModel:WizardSchoolclassSubjectPageViewModel}"> <View:WizardSchoolclassSubjectPageView /> </DataTemplate> <DataTemplate DataType="{x:Type ViewModel:WizardLessonTimesPageViewModel}"> <View:WizardLessonTimesPageView /> </DataTemplate> <DataTemplate DataType="{x:Type ViewModel:WizardTimeTablePageViewModel}"> <View:WizardTimeTablePageView /> </DataTemplate> <DataTemplate DataType="{x:Type ViewModel:WizardFinishPageViewModel}"> <View:WizardFinishPageView /> </DataTemplate> <!-- This Style inherits from the Button style seen above. --> <Style BasedOn="{StaticResource {x:Type Button}}" TargetType="{x:Type Button}" x:Key="moveNextButtonStyle"> <Setter Property="Content" Value="Next" /> <Style.Triggers> <DataTrigger Binding="{Binding Path=IsOnLastPage}" Value="True"> <Setter Property="Content" Value="Finish}" /> </DataTrigger> </Style.Triggers> </Style> <ViewModel:WizardMainViewModel x:Key="WizardMainViewModelID" /> </UserControl.Resources> <Grid DataContext="{Binding ., Source={StaticResource WizardMainViewModelID}}" > <Grid.RowDefinitions> <RowDefinition Height="310*" /> <RowDefinition Height="51*" /> </Grid.RowDefinitions> <!-- CONTENT --> <Grid Grid.Row="0" Background="LightGoldenrodYellow"> <HeaderedContentControl Content="{Binding CurrentPage}" Header="{Binding Path=CurrentPage.DisplayName}" /> </Grid> <!-- NAVIGATION BUTTONS --> <Grid Grid.Row="1" Background="Aquamarine"> <StackPanel HorizontalAlignment="Center" Orientation="Horizontal"> <Button Command="{Binding MovePreviousCommand}" Content="Previous" /> <Button Command="{Binding MoveNextCommand}" Style="{StaticResource moveNextButtonStyle}" Content="Next" /> <Button Command="{Binding CancelCommand}" Content="Cancel" /> </StackPanel> </Grid> </Grid>

    Read the article

  • Style Trigger on Attached Property

    - by vanja.
    I have created my own Attached Property like this: public static class LabelExtension { public static bool GetSelectable(DependencyObject obj) { return (bool)obj.GetValue(SelectableProperty); } public static void SetSelectable(DependencyObject obj, bool value) { obj.SetValue(SelectableProperty, value); } // Using a DependencyProperty as the backing store for Selectable. This enables animation, styling, binding, etc... public static readonly DependencyProperty SelectableProperty = DependencyProperty.RegisterAttached("Selectable", typeof(bool), typeof(Label), new UIPropertyMetadata(false)); } And then I'm trying to create a style with a trigger that depends on it: <!--Label--> <Style TargetType="{x:Type Label}"> <Style.Triggers> <Trigger Property="Util:LabelExtension.Selectable" Value="True"> <Setter Property="Template"> <Setter.Value> <ControlTemplate TargetType="{x:Type Label}"> <TextBox IsReadOnly="True" Text="{TemplateBinding Content}" /> </ControlTemplate> </Setter.Value> </Setter> </Trigger> </Style.Triggers> </Style> But I'm getting a run time exception: Cannot convert the value in attribute 'Property' to object of type 'System.Windows.DependencyProperty'. Error at object 'System.Windows.Trigger' in markup file How can I access the value of the attached property in a style trigger? I have tried using a DataTrigger with a RelativeSource binding but it wasn't pulling the value through.

    Read the article

  • Silverlight Cream for December 18, 2010 -- #1012

    - by Dave Campbell
    In this Issue: Mark Monster, Kevin Dockx, Jeremy Likness(-2-,-3-), Timmy Kokke, Den Delimarsky, Mike Snow, Samuel Jack(-2-), and Renuka Prasad(-2-). Above the Fold: Silverlight: "Trigger a Storyboard on ViewModel changes" Mark Monster WP7: "Microsoft Push Notification in Windows Phone 7" Renuka Prasad Shoutouts: SilverlightGal sent me the link to The Silverlight Dossier ... I think it's a pretty good start... additions I'd like to see are ways to submit to the various areas. Michael Crump put up a contest that runs from now to January 1st... Win a set of Infragistics Silverlight Controls with Data Visualization!... pretty cool, Michael! If you visit WynApse.com, you'll see I have a subscription to LearnVisualStudio.net... and now they have posted a batch of WP7 videos... 64 of them to be exact... wow!: New video series From SilverlightCream.com: Trigger a Storyboard on ViewModel changes Mark Monster has a great post up about triggering Storyboard on ViewModel changes using the DataTrigger from Blend... cool stuff, and you can also do GoToStateAction or other actions or build yourowndang Trigger Action... fun awaits! ... sorry it took a while to post, Mark... been a tad overloaded here! Working with the Silverlight Rich Text Box control Kevin Dockx has had a post up for a while at SilverlightShow where he takes a good look at the RichText control and it's various capabilities, including source so you can give it a dance yourself. Lessons Learned in Personal Web Page Part 3: Custom Panel and Listbox Jeremy Likness's part 3 of his Personal Web Page lessons learned is covering the tres-cool 3D Panel he did... and he's got it all explained out... building from scratch via a custom panel and a Listbox control... A Silverlight MVVM Feed Reader from Scratch in 30 Minutes Jeremy Likness has a video tutorial showing building an MVVM/Silverlight feedreader in 30 minutes ... plus a couple mods that he noticed after the fact... beat that HTML5 :) Jounce Part 8: Raising Property Changed In Jeremy Likness's latest post, he has number 8 in his series on his MVVM platform, Jounce. This time he's explaining the property changed notification, has a very cool way of doing it, and some interesting comments from readers. Dependency Injection, MVVM, Ninject and Silverlight Timmy Kokke has a great tutorial up with associated demo project on Dependency Injection in MVVM and Silverlight. Some hidden features in the Windows Phone 7 emulator Den Delimarsky shows how to get some of the hidden features on your WP7 emulator like the Call History, Call Settings, and Details about the numbers. Playing sound effects on Windows Phone 7 Mike Snow's latest tip is playing sound effects on your WP7 ... a little bit of XNA here and there, and badabing, badaboom, you got sound! Day 3 of my “Build a Windows Phone 7 game in 3 days” Challenge Samuel Jack has a couple more posts up about his 'Build a WP7 game in 3 Days' challenge... first up is Day 3 from 8:50 to 22:30 ... wow... long day! ... but he's got something good going now... some good external links also Day 3.5 of my “Build a Windows Phone 7 game in 3 days” Challenge Samuel Jack's 3rd day ended with another half-day added on to put on some finishing touches... again, some good external links... and he finished with this Say hello to Simon Squared, my 3.5 day old WP7 Game Microsoft Push Notification in Windows Phone 7 Renuka Prasad has a bunch of material up that I've not been aware of (how did that happen, people??) ... here's the first of a couple of his posts on Code Project ... a very nice tutorial on the Push Notification process... great diagrams and external links. Windows Phone 7 – Toast Notification Using Windows Azure Cloud Service Renuka Prasad has another WP7 post on CodeProject... this one on Toast Notification... and he's using Azure and WCF all rolled into it as well... great diagrams, descriptions and all the code. Stay in the 'Light! Twitter SilverlightNews | Twitter WynApse | WynApse.com | Tagged Posts | SilverlightCream Join me @ SilverlightCream | Phoenix Silverlight User Group Technorati Tags: Silverlight    Silverlight 3    Silverlight 4    Windows Phone MIX10

    Read the article

  • WPF TreeView MouseDown

    - by imekon
    I've got something like this in a TreeView: <DataTemplate x:Key="myTemplate"> <StackPanel MouseDown="OnItemMouseDown"> ... </StackPanel> </DataTemplate> Using this I get the mouse down events if I click on items in the stack panel. However... there seems to be another item behind the stack panel that is the TreeViewItem - it's very hard to hit, but not impossible, and that's when the problems start to occur. I had a go at handling PreviewMouseDown on TreeViewItem, however that seems to require e.Handled = false otherwise standard tree view behaviour stops working. Ok, Here's the source code... MainWindow.xaml <Window x:Class="WPFMultiSelectTree.MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:local="clr-namespace:WPFMultiSelectTree" Title="Multiple Selection Tree" Height="300" Width="300"> <Window.Resources> <!-- Declare the classes that convert bool to Visibility --> <local:VisibilityConverter x:Key="visibilityConverter"/> <local:VisibilityInverter x:Key="visibilityInverter"/> <!-- Set the style for any tree view item --> <Style TargetType="TreeViewItem"> <Style.Triggers> <DataTrigger Binding="{Binding Selected}" Value="True"> <Setter Property="Background" Value="DarkBlue"/> <Setter Property="Foreground" Value="White"/> </DataTrigger> </Style.Triggers> <EventSetter Event="PreviewMouseDown" Handler="OnTreePreviewMouseDown"/> </Style> <!-- Declare a hierarchical data template for the tree view items --> <HierarchicalDataTemplate x:Key="RecursiveTemplate" ItemsSource="{Binding Children}"> <StackPanel Margin="2" Orientation="Horizontal" MouseDown="OnTreeMouseDown"> <Ellipse Width="12" Height="12" Fill="Green"/> <TextBlock Margin="2" Text="{Binding Name}" Visibility="{Binding Editing, Converter={StaticResource visibilityInverter}}"/> <TextBox Margin="2" Text="{Binding Name}" KeyDown="OnTextBoxKeyDown" IsVisibleChanged="OnTextBoxIsVisibleChanged" Visibility="{Binding Editing, Converter={StaticResource visibilityConverter}}"/> <TextBlock Margin="2" Text="{Binding Index, StringFormat=({0})}"/> </StackPanel> </HierarchicalDataTemplate> <!-- Declare a simple template for a list box --> <DataTemplate x:Key="ListTemplate"> <TextBlock Text="{Binding Name}"/> </DataTemplate> </Window.Resources> <Grid> <!-- Declare the rows in this grid --> <Grid.RowDefinitions> <RowDefinition Height="Auto"/> <RowDefinition/> <RowDefinition Height="Auto"/> <RowDefinition/> </Grid.RowDefinitions> <!-- The first header --> <TextBlock Grid.Row="0" Margin="5" Background="PowderBlue">Multiple selection tree view</TextBlock> <!-- The tree view --> <TreeView Name="m_tree" Margin="2" Grid.Row="1" ItemsSource="{Binding Children}" ItemTemplate="{StaticResource RecursiveTemplate}"/> <!-- The second header --> <TextBlock Grid.Row="2" Margin="5" Background="PowderBlue">The currently selected items in the tree</TextBlock> <!-- The list box --> <ListBox Name="m_list" Margin="2" Grid.Row="3" ItemsSource="{Binding .}" ItemTemplate="{StaticResource ListTemplate}"/> </Grid> </Window> MainWindow.xaml.cs /// <summary> /// Interaction logic for MainWindow.xaml /// </summary> public partial class MainWindow : Window { private Container m_root; private Container m_first; private ObservableCollection<Container> m_selection; private string m_current; /// <summary> /// Constructor /// </summary> public MainWindow() { InitializeComponent(); m_selection = new ObservableCollection<Container>(); m_root = new Container("root"); for (int parents = 0; parents < 50; parents++) { Container parent = new Container(String.Format("parent{0}", parents + 1)); for (int children = 0; children < 1000; children++) { parent.Add(new Container(String.Format("child{0}", children + 1))); } m_root.Add(parent); } m_tree.DataContext = m_root; m_list.DataContext = m_selection; m_first = null; } /// <summary> /// Has the shift key been pressed? /// </summary> private bool ShiftPressed { get { return Keyboard.IsKeyDown(Key.LeftShift) || Keyboard.IsKeyDown(Key.RightShift); } } /// <summary> /// Has the control key been pressed? /// </summary> private bool CtrlPressed { get { return Keyboard.IsKeyDown(Key.LeftCtrl) || Keyboard.IsKeyDown(Key.RightCtrl); } } /// <summary> /// Clear down the selection list /// </summary> private void DeselectAndClear() { foreach(Container container in m_selection) { container.Selected = false; } m_selection.Clear(); } /// <summary> /// Add the container to the list (if not already present), /// mark as selected /// </summary> /// <param name="container"></param> private void AddToSelection(Container container) { if (container == null) { return; } foreach (Container child in m_selection) { if (child == container) { return; } } container.Selected = true; m_selection.Add(container); } /// <summary> /// Remove container from list, mark as not selected /// </summary> /// <param name="container"></param> private void RemoveFromSelection(Container container) { m_selection.Remove(container); container.Selected = false; } /// <summary> /// Process single click on a tree item /// /// Normally just select an item /// /// SHIFT-Click extends selection /// CTRL-Click toggles a selection /// </summary> /// <param name="sender"></param> private void OnTreeSingleClick(object sender) { FrameworkElement element = sender as FrameworkElement; if (element != null) { Container container = element.DataContext as Container; if (container != null) { if (CtrlPressed) { if (container.Selected) { RemoveFromSelection(container); } else { AddToSelection(container); } } else if (ShiftPressed) { if (container.Parent == m_first.Parent) { if (container.Index < m_first.Index) { Container item = container; for (int i = container.Index; i < m_first.Index; i++) { AddToSelection(item); item = item.Next; if (item == null) { break; } } } else if (container.Index > m_first.Index) { Container item = m_first; for (int i = m_first.Index; i <= container.Index; i++) { AddToSelection(item); item = item.Next; if (item == null) { break; } } } } } else { DeselectAndClear(); m_first = container; AddToSelection(container); } } } } /// <summary> /// Process double click on tree item /// </summary> /// <param name="sender"></param> private void OnTreeDoubleClick(object sender) { FrameworkElement element = sender as FrameworkElement; if (element != null) { Container container = element.DataContext as Container; if (container != null) { container.Editing = true; m_current = container.Name; } } } /// <summary> /// Clicked on the stack panel in the tree view /// /// Double left click: /// /// Switch to editing mode (flips visibility of textblock and textbox) /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void OnTreeMouseDown(object sender, MouseButtonEventArgs e) { Debug.WriteLine("StackPanel mouse down"); switch(e.ChangedButton) { case MouseButton.Left: switch (e.ClickCount) { case 2: OnTreeDoubleClick(sender); e.Handled = true; break; } break; } } /// <summary> /// Clicked on tree view item in tree /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void OnTreePreviewMouseDown(object sender, MouseButtonEventArgs e) { Debug.WriteLine("TreeViewItem preview mouse down"); switch (e.ChangedButton) { case MouseButton.Left: switch (e.ClickCount) { case 1: { // We've had a single click on a tree view item // Unfortunately this is the WHOLE tree item, including the +/- // symbol to the left. The tree doesn't do a selection, so we // have to filter this out... MouseDevice device = e.Device as MouseDevice; Debug.WriteLine(String.Format("Tree item clicked on: {0}", device.DirectlyOver.GetType().ToString())); // This is bad. The whole point of WPF is for the code // not to know what the UI has - yet here we are testing for // it as a workaround. Sigh... if (device.DirectlyOver.GetType() != typeof(Path)) { OnTreeSingleClick(sender); } // Cannot say handled - if we do it stops the tree working! //e.Handled = true; } break; } break; } } /// <summary> /// Key press in text box /// /// Return key finishes editing /// Escape key finishes editing, restores original value (this doesn't work!) /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void OnTextBoxKeyDown(object sender, KeyEventArgs e) { switch(e.Key) { case Key.Return: { TextBox box = sender as TextBox; if (box != null) { Container container = box.DataContext as Container; if (container != null) { container.Editing = false; e.Handled = true; } } } break; case Key.Escape: { TextBox box = sender as TextBox; if (box != null) { Container container = box.DataContext as Container; if (container != null) { container.Editing = false; container.Name = m_current; e.Handled = true; } } } break; } } /// <summary> /// When text box becomes visible, grab focus and select all text in it. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void OnTextBoxIsVisibleChanged(object sender, DependencyPropertyChangedEventArgs e) { bool visible = (bool)e.NewValue; if (visible) { TextBox box = sender as TextBox; if (box != null) { box.Focus(); box.SelectAll(); } } } } Here's the Container class public class Container : INotifyPropertyChanged { private string m_name; private ObservableCollection<Container> m_children; private Container m_parent; private bool m_selected; private bool m_editing; /// <summary> /// Constructor /// </summary> /// <param name="name">name of object</param> public Container(string name) { m_name = name; m_children = new ObservableCollection<Container>(); m_parent = null; m_selected = false; m_editing = false; } /// <summary> /// Name of object /// </summary> public string Name { get { return m_name; } set { if (m_name != value) { m_name = value; OnPropertyChanged("Name"); } } } /// <summary> /// Index of object in parent's children /// /// If there's no parent, the index is -1 /// </summary> public int Index { get { if (m_parent != null) { return m_parent.Children.IndexOf(this); } return -1; } } /// <summary> /// Get the next item, assuming this is parented /// /// Returns null if end of list reached, or no parent /// </summary> public Container Next { get { if (m_parent != null) { int index = Index + 1; if (index < m_parent.Children.Count) { return m_parent.Children[index]; } } return null; } } /// <summary> /// List of children /// </summary> public ObservableCollection<Container> Children { get { return m_children; } } /// <summary> /// Selected status /// </summary> public bool Selected { get { return m_selected; } set { if (m_selected != value) { m_selected = value; OnPropertyChanged("Selected"); } } } /// <summary> /// Editing status /// </summary> public bool Editing { get { return m_editing; } set { if (m_editing != value) { m_editing = value; OnPropertyChanged("Editing"); } } } /// <summary> /// Parent of this object /// </summary> public Container Parent { get { return m_parent; } set { m_parent = value; } } /// <summary> /// WPF Property Changed event /// </summary> public event PropertyChangedEventHandler PropertyChanged; /// <summary> /// Handler to inform WPF that a property has changed /// </summary> /// <param name="name"></param> private void OnPropertyChanged(string name) { if (PropertyChanged != null) { PropertyChanged(this, new PropertyChangedEventArgs(name)); } } /// <summary> /// Add a child to this container /// </summary> /// <param name="child"></param> public void Add(Container child) { m_children.Add(child); child.m_parent = this; } /// <summary> /// Remove a child from this container /// </summary> /// <param name="child"></param> public void Remove(Container child) { m_children.Remove(child); child.m_parent = null; } } The two classes VisibilityConverter and VisibilityInverter are implementations of IValueConverter that translates bool to Visibility. They make sure the TextBlock is displayed when not editing, and the TextBox is displayed when editing.

    Read the article

  • Visual Studio soft-crashing when encountering XAML Errors in initialize.

    - by Aren
    I've been having some serious issues with Visual Studio 2010 as of late. It's been crashing in a peculiar way when I encounter certain types of XAML errors during the InitializeComponent() of a control/window. The program breaks and visual studio gears up like it's catching an exception (because it is) and then stops midway displaying a broken highlight in my XAML file with no details as to what is wrong. Example: There is not pop outs, or details Anywhere about what is wrong, only a callstack that points to my InitializeComponent() call. Now normally I'd just do some trial and error to fix this problem, and find out where i messed up, but the real problem isn't my code. Visual Studio is rendered completely useless at this point. It reports my application still in "Running" mode. The Stop/Break/Restart buttons on the toolbar or in the menus don't do anything (but grey out). Closing the application does not stop this behaviour, closing visual studio gets it stuck in a massive loop where it yells at me complaining every file open is not in the debug project, then repeats this process when i have exausted every open file. I have to force-close devenv.exe, and after this happening 3-4 times in a row it's a lot of wasted time (as my projects are usually pretty big and studio can be quite slow @ loading). To the point Has anyone else experienced this? How can I stop studio from locking up. Can I at LEAST get information out of this beast another way so i can fix my XAML error sooner rather than after 3-4 trial-and-error compiles yielding the same crash? Any & All help would be appreciated. Visual Studio 2010 version: 10.0.30319.1RTM Edit & Update FWIW, mostly the errors that cause this are XamlParseExceptions (I figured this out after i found what was wrong with my XAML). I think I need to be clearer though, Im not looking for the solution to my code problem, as these are usually typos / small things, I'm looking for a solution to VStudio getting all buggered up as a result. The particular error in the above image that 100% for sure caused this was a XamlParseException caused by forgetting a Value attribute on a data trigger. I've fixed that part but it still doesn't tell my why my studio becomes a lump of neutered program when a perfectly normal exception is thrown in the parsing of the XAML. Code that will cause this issue (at least for me) This is the base template WPF Application, with the following Window.xaml code. The problem is a missing Value="True" on the <DataTrigger ...> in the template. It generates a XamlParseException and Visual Studio Crashes as described above when debugging it. Final Notes The following solutions did not help me: Restarting Visual Studio Rebooting Reinstalling Visual Studio

    Read the article

< Previous Page | 1 2 3