Click here to Skip to main content
15,901,373 members
Home / Discussions / WPF
   

WPF

 
QuestionCreating Custom Button control using Asp.Net Pin
VijaySofist1-Jun-08 19:20
VijaySofist1-Jun-08 19:20 
AnswerRe: Creating Custom Button control using Asp.Net Pin
Michael Sync2-Jun-08 18:14
Michael Sync2-Jun-08 18:14 
GeneralRe: Creating Custom Button control using Asp.Net Pin
Michael Sync2-Jun-08 18:15
Michael Sync2-Jun-08 18:15 
QuestionRe: Creating Custom Button control using Asp.Net Pin
VijaySofist3-Jun-08 18:45
VijaySofist3-Jun-08 18:45 
AnswerRe: Creating Custom Button control using Asp.Net Pin
Michael Sync4-Jun-08 20:16
Michael Sync4-Jun-08 20:16 
QuestionRe: Creating Custom Button control using Asp.Net Pin
VijaySofist4-Jun-08 23:59
VijaySofist4-Jun-08 23:59 
AnswerRe: Creating Custom Button control using Asp.Net Pin
Michael Sync5-Jun-08 2:20
Michael Sync5-Jun-08 2:20 
AnswerScaling woes Pin
Ray Hayes1-Jun-08 6:01
Ray Hayes1-Jun-08 6:01 
Hi,

I'm trying to get my mind around a problem I'm having with WPF. It can easily be compared to something like a stacked-bar chart (BTW, that's not what I'm creating, so please don't point me to a library providing these). Visually the results should look something like this:

NameA |-----||-----------||----|<br />
NameB |---------||-----------------|<br />
NameC |---||----------||-|


At the moment I have an Observable collection of data that provides me with two types, the string for the name and another collection with the values. I have used a ListView to display my table and the values are represented by an ItemsControl putting the data values inside a horizontally organized StackPanel.
<ListView ItemsSource="{Binding Source={StaticResource ResourceKey=data}}" Grid.Row="0" x:Name="myGrid">
    <ListView.View>
        <GridView>
            <GridViewColumn Header="Name" DisplayMemberBinding="{Binding Path=Name}"/>
            <GridViewColumn Header="Values">
                <GridViewColumn.CellTemplate>
                    <DataTemplate>
                        <!-- Bind each item to the valueTemplate -->
                        <ItemsControl ItemsSource="{Binding Path=Values}" 
                                      ItemTemplate="{StaticResource valueTemplate}">
                            <ItemsControl.ItemsPanel>
                                <ItemsPanelTemplate>
                                    <StackPanel Orientation="Horizontal"/>
                                </ItemsPanelTemplate>
                            </ItemsControl.ItemsPanel>
                        </ItemsControl>
                    </DataTemplate>
                </GridViewColumn.CellTemplate>
            </GridViewColumn>
        </GridView>
    </ListView.View>
</ListView>
The valueTemplate is implemented as this in the Windows.Resources block:
<DataTemplate x:Key="valueTemplate">
    <Border Width="{Binding}" CornerRadius="2" >
        <TextBlock Text="{Binding Title}" FontWeight="Bold" />
    </Border>
</DataTemplate>
Notice that the Width is, in the example above, set by a TypeConverter which takes an object of my datatype and returns a double corresponding to the width I want.

This works and the appearence is as desired. What I want to do now is make the "scale" of the displayed data change (not everything) e.g. if the value is 10, it is currently displayed as 10 pixels wide. I'd like to be able to adjust a slider to 2.0 and have the displayed data show as 20 pixels wide.

To attempt this, I've tried two main things:
  • Having my slider update a value that the TypeConverter can see. When doing this, I can not seem to find any way to make the controls "redraw" using my new values. This also feels the wrong way to do things as the backend shouldn't need logic to affect the displayed output!
  • Having the slider start animating the ScaleX element of a modified valueTemplate.
For the scaling, I've added the following to the valueTemplate
<Border.LayoutTransform>
    <ScaleTransform x:Name="myScale" ScaleX="1.0" ScaleY="1.0" />
</Border.LayoutTransform>
and a Slider like this:
<Slider x:Name="Scale" Width="100" Minimum="0.5" Maximum="10.0" Value="1.0">
    <Slider.Triggers>
        <EventTrigger RoutedEvent="Slider.ValueChanged">
            <EventTrigger.Actions>
                <BeginStoryboard>
                    <Storyboard>
                        <DoubleAnimation Storyboard.TargetName="myScale" 
                                         Storyboard.TargetProperty="ScaleX" 
                                         To="{Binding ElementName=Scale,Path=Value}"/>
                    </Storyboard>
                </BeginStoryboard>
            </EventTrigger.Actions>
        </EventTrigger>
    </Slider.Triggers>
</Slider>
The above code gives me an error 'myScale' name cannot be found in the name scope of 'System.Windows.Controls.Slider'. which makes some sense to me, but I can't see how to address the "name" defined inside of a template.

I've now hit a wall and don't know where to go next! Should I be defining a simple double in my resources and changing that? How can I define that (I assume I need to bring in some other namespace)? Can simple math be performed inside something like a Width field? Can anyone help me?

Regards,
Ray

GeneralRe: Scaling woes Pin
TJoe3-Jun-08 2:22
TJoe3-Jun-08 2:22 
GeneralRe: Scaling woes Pin
Ray Hayes3-Jun-08 11:40
Ray Hayes3-Jun-08 11:40 
GeneralRe: Scaling woes Pin
Ray Hayes3-Jun-08 11:53
Ray Hayes3-Jun-08 11:53 
GeneralRe: Scaling woes Pin
TJoe4-Jun-08 1:56
TJoe4-Jun-08 1:56 
GeneralRe: Scaling woes Pin
Ray Hayes4-Jun-08 2:10
Ray Hayes4-Jun-08 2:10 
GeneralRe: Scaling woes Pin
TJoe4-Jun-08 2:13
TJoe4-Jun-08 2:13 
GeneralRe: Scaling woes Pin
Ray Hayes4-Jun-08 2:22
Ray Hayes4-Jun-08 2:22 
GeneralRe: Scaling woes Pin
TJoe4-Jun-08 2:25
TJoe4-Jun-08 2:25 
GeneralRe: Scaling woes Pin
Ray Hayes4-Jun-08 2:32
Ray Hayes4-Jun-08 2:32 
GeneralRe: Scaling woes Pin
TJoe4-Jun-08 2:37
TJoe4-Jun-08 2:37 
GeneralRe: Scaling woes Pin
Ray Hayes4-Jun-08 2:45
Ray Hayes4-Jun-08 2:45 
GeneralRe: Scaling woes Pin
TJoe4-Jun-08 2:47
TJoe4-Jun-08 2:47 
GeneralRe: Scaling woes Pin
TJoe4-Jun-08 2:50
TJoe4-Jun-08 2:50 
GeneralRe: Scaling woes Pin
Ray Hayes4-Jun-08 2:52
Ray Hayes4-Jun-08 2:52 
GeneralRe: Scaling woes Pin
Member 36739221-Jul-09 19:56
Member 36739221-Jul-09 19:56 
Questionerror while opening new window from a Asynchronou callback function Pin
vayanan31-May-08 11:15
vayanan31-May-08 11:15 
AnswerRe: error while opening new window from a Asynchronou callback function Pin
User 2710091-Jun-08 11:25
User 2710091-Jun-08 11:25 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.