locked
Change Control Property value in VSM RRS feed

  • Question

  • Is it possible to chnage the default property value of a control in VSM..

    say for example, I have a TextBox control and I need to change the FontFamily in its disabled state...

    Any ideas?

    Sunday, September 18, 2011 1:59 AM

Answers

  • Ah ok, I understand. Yes, the solution provided there seems legit for this kind of changes, even though it's not pretty.

    Sunday, September 18, 2011 9:03 AM

All replies

  • Hi Neal. Sure, that is exactly what visual states are for. It's simplest to do this in Blend, but you can of course also write the states manually. For example:

    <Grid x:Name="LayoutRoot">
    	<VisualStateManager.VisualStateGroups>
    		<VisualStateGroup x:Name="VisualStateGroup">
    			<VisualState x:Name="Normal"/>
    			<VisualState x:Name="Weird">
    				<Storyboard>
    					<ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="(TextBlock.FontFamily)" Storyboard.TargetName="textBlock">
    						<DiscreteObjectKeyFrame KeyTime="0">
    							<DiscreteObjectKeyFrame.Value>
    								<FontFamily>Comic Sans MS</FontFamily>
    							</DiscreteObjectKeyFrame.Value>
    						</DiscreteObjectKeyFrame>
    					</ObjectAnimationUsingKeyFrames>
    					<DoubleAnimation Duration="0" To="24" Storyboard.TargetProperty="(TextBlock.FontSize)" Storyboard.TargetName="textBlock" d:IsOptimized="True"/>
    				</Storyboard>
    			</VisualState>
    		</VisualStateGroup>
    	</VisualStateManager.VisualStateGroups>
    	<TextBlock x:Name="textBlock" HorizontalAlignment="Center" TextWrapping="Wrap" Text="TEST" VerticalAlignment="Center"/>
    </Grid>
    Sunday, September 18, 2011 2:50 AM
  • Thanks a lot for your quick reply Mr. Goodcat, But I was expecting a generic kind of solution; say In the Template Setter of TextBox Style;

    Since, there is'nt a Content Presenter kind of thing for the TextBox control, I am not able to set the IsTabStop property in Disabled or Read only state for all the textbox; I tried setting it without a Target name and the application / page crashes.

    What you have mentioned is correct in a form or a Custom Control; Sorry about the unclear question.

    Sunday, September 18, 2011 3:21 AM
  • Since, there is'nt a Content Presenter kind of thing for the TextBox control

    Yes, the textbox uses a control part for the content (and assumes that it's a scroll viewer for certain features to work).

    What exactly are you trying to do? In the first post you mentioned font properties; now the tab stop property. Can't what you need be done by creating a copy of the default style of the text box and making the adjustments there?

    Sunday, September 18, 2011 5:23 AM
  • I added TabStop Property in the second post just to make a general statement.

    What I want is to edit the VSM in the template (in style) of a TextBox to change some of the basic properties of a TextBox in different states; this should be applied for a set of TextBoxes, thatz why I want it in the generic style

    For example:

    Normal State: TextBox.FontFamily = "Arial" IsTabStop="true" FontSize="10"
    Disabled State: TextBox.FontFamily = "Tahoma" IsTabStop="false" FontSize="8"

    I guess, now you have an idea about what exactly I think...

    Sunday, September 18, 2011 6:13 AM
  • Dear..

    I need something like this... But adding a textbox within the style doesn't seems like a good practice. I guess, you have a much clear picture of what I am trying to depict

    Sunday, September 18, 2011 6:24 AM
  • Ah ok, I understand. Yes, the solution provided there seems legit for this kind of changes, even though it's not pretty.

    Sunday, September 18, 2011 9:03 AM