1 Replies - 6349 Views - Last Post: 06 August 2013 - 01:40 AM Rate Topic: -----

#1 DevJunk  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 12-January 11

How to swicth the Style of a Item?

Posted 01 August 2013 - 06:51 AM

I created a trigger to modified the style, but does not work

<Setter TargetName="continuosmedicationBorder" Property="Style" Value="BrokenContinuousMedicationAdministrationBorderStyle"/>


all I want is that changes the style when a certain property is true, in this case is the property: IsBrokendAdministration


CAN SOMEBODY HELP ME ?!!! thanks GUYS

<UserControl x:Class="Mag.Mcc.Module.MedicalRecords.Presentation.Medications.Views.MedicationView3Control"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:helpers="clr-namespace:Mag.Mcc.Module.MedicalRecords.Presentation.Helpers;assembly=Mag.Mcc.Module.MedicalRecords.Presentation"
    xmlns:vm="clr-namespace:Mag.Mcc.Module.MedicalRecords.Presentation.ViewModels;assembly=Mag.Mcc.Module.MedicalRecords.Presentation"
    xmlns:view="clr-namespace:Mag.Mcc.Module.MedicalRecords.Presentation.Medications.Views"
    vm:CommandSinkBinding.CommandSink="{Binding}" 
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
    xmlns:viewModels="clr-namespace:Mag.Mcc.Module.MedicalRecords.Presentation.Medications.ViewModels" 
    mc:Ignorable="d" d:DesignWidth="519" d:DesignHeight="379" x:Name="userControl" >

	<!-- Dieses Control wird für Medikamente mit kontinuierlicher Gabe verwendet -->
	<!-- DATACONTEXT MedicationViewModel -->


	<UserControl.Resources>
		<ResourceDictionary>
			<ResourceDictionary.MergedDictionaries>
				<ResourceDictionary Source="../Resources/CommonResources.xaml" />
			</ResourceDictionary.MergedDictionaries>

			<CollectionViewSource x:Key="viewSource" Source="{Binding Path=Administrations, Mode=OneWay}">
			</CollectionViewSource>
		</ResourceDictionary>		
	</UserControl.Resources>

	<Grid >
		<ItemsControl ItemsSource="{Binding Source={StaticResource viewSource}}">
			<ItemsControl.ItemsPanel>
				<ItemsPanelTemplate>
					<Canvas />
				</ItemsPanelTemplate>
			</ItemsControl.ItemsPanel>
			<ItemsControl.ItemTemplate>				
				<DataTemplate DataType="x:Type viewModel:MedicationAdministrationViewModel">
					<Border x:Name="continuosmedicationBorder" Style="{StaticResource ContinuousMedicationAdministrationBorderStyle}"
                            Height="{Binding ActualHeight, ElementName=userControl, Mode=OneWay}" 
					        Width="{Binding CalculatedWidth, Mode=OneWay}" ToolTip="{StaticResource MedicationAdministrationTooltip}">

						<StackPanel Orientation="Horizontal">							
							<view:MedicationSeparatorControl x:Name="startSeparator" Visibility="Hidden" 
                                                             IsStart="True" IsEnd="False" 
                                                             MinWidth="20" />							
							<TextBlock x:Name="medicationAdministrationTextBlock" Text="{Binding Path=CountText, Mode=OneWay}"
                                                   Style="{StaticResource ContinuousMedicationAdministrationTextStyle}" 
                                                   ToolTip="{StaticResource ContinuousMedicationAdministrationTooltip}"
                                                   MouseLeftButtonDown="MedicationText_MouseLeftButtonDown" >

							</TextBlock>

							<!--<TextBlock x:Name="medicationAdministrationTextBlockbroken" Text="{Binding Path=CountText, Mode=OneWay}"
                                                   Style="{StaticResource BrokedContinuousMedicationAdministrationTextStyle}" 
                                                   ToolTip="{StaticResource ContinuousMedicationAdministrationTooltip}"
                                                   MouseLeftButtonDown="MedicationText_MouseLeftButtonDown" Visibility="{Binding Path=IsBrokendAdministration, Mode=OneWay}" >
							</TextBlock>-->
							<TextBlock Text="(B)/>/>" ToolTip="{Binding Path=Annotation, Mode=OneWay}" Style="{StaticResource MedicationAdministrationTextStyle}"
                                           Visibility="{Binding Path=HasAnnotation, Mode=OneWay, Converter={StaticResource BooleanToVisibilityConverter}}" />
							<view:MedicationSeparatorControl x:Name="endSeparator" Visibility="Hidden" MinWidth="20"
                                                             IsStart="False" IsEnd="True"   />
						</StackPanel>

					</Border>					
					<DataTemplate.Triggers>
						<DataTrigger Binding="{Binding Path=IsFirstAdministration, Mode=OneWay}" Value="True">
							<Setter TargetName="startSeparator" Property="Visibility" Value="Visible"/>
						</DataTrigger>
						<DataTrigger Binding="{Binding Path=IsLastAdministration, Mode=OneWay}" Value="True">
							<Setter TargetName="endSeparator" Property="Visibility" Value="Visible"/>
						</DataTrigger>
						<DataTrigger Binding="{Binding Path=IsBrokendAdministration, Mode=OneWay}" Value="True">
							<Setter TargetName="continuosmedicationBorder" Property="Style" Value="BrokenContinuousMedicationAdministrationBorderStyle"/>
						</DataTrigger>
					</DataTemplate.Triggers>
				</DataTemplate>
			</ItemsControl.ItemTemplate>
			<ItemsControl.ContextMenu>
				<ContextMenu vm:CommandSinkBinding.CommandSink="{Binding}">
					<ContextMenu.CommandBindings>
						<vm:CommandSinkBinding Command="viewModels:MedicationViewModel.CreateCommand" />
					</ContextMenu.CommandBindings>

					<MenuItem Header="{helpers:TextLocalizer 1057041}" Command="viewModels:MedicationViewModel.CreateCommand" />
					<MenuItem Header="{helpers:TextLocalizer 1057071}" Click="MenuItem_Click" />
				</ContextMenu>
			</ItemsControl.ContextMenu>
			<ItemsControl.ItemContainerStyle>
				<Style>
					<Setter Property="Canvas.Left" Value="{Binding Path=CalculatedLeft, Mode=OneWay}"/>
					<Setter Property="Canvas.Top"  Value="0"/>
				</Style>
			</ItemsControl.ItemContainerStyle>
		</ItemsControl>
	</Grid>

</UserControl>



Is This A Good Question/Topic? 0
  • +

Replies To: How to swicth the Style of a Item?

#2 MrShoes  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 313
  • View blog
  • Posts: 490
  • Joined: 13-June 12

Re: How to swicth the Style of a Item?

Posted 06 August 2013 - 01:40 AM

I think it's because you're passing a string to the Style property. How does the XAML know how to interpret that string? You need to set the style as a resource, not a string, like {StaticResource BrokenContinuousMedicationAdministrationBorderStyle}. See if that works.
Was This Post Helpful? 1
  • +
  • -

Page 1 of 1