locked
Change image Height and Width dynamically in Windows store apps

    Question

  • Hi,

    I have two text Box,one for Height(txtHeight)and another for Width(txtWidth).

    I display image with some default width and height.I want to change image width and height dynamically when the values of  txtHeight/txtWidth  changes.

    We have followed MVVM for the code.

    Can some one share a sample code for it.or any solution on it?

    Thursday, December 18, 2014 7:52 AM

Answers

  • Try this

        <Grid x:Name="ContentPanel" Grid.Row="1" Margin="12,0,12,0">
            <Grid.RowDefinitions >
                <RowDefinition Height="*"/>
                <RowDefinition Height="Auto"/>
            </Grid.RowDefinitions>
            <Image x:Name="image" Width="10" Height="10" Source="Assets/1.jpg" Stretch="Fill" />
            <StackPanel Grid.Row="1" >
                <TextBox x:Name="txt1" Text="{Binding ElementName=image ,Path=Width , Mode=TwoWay ,UpdateSourceTrigger=PropertyChanged}"/>
                <TextBox x:Name="txt2" Text="{Binding ElementName=image ,Path=Height , Mode=TwoWay ,UpdateSourceTrigger=PropertyChanged}"/>
            </StackPanel>
    
    
        </Grid>


    在現實生活中,你和誰在一起的確很重要,甚至能改變你的成長軌跡,決定你的人生成敗。 和什麼樣的人在一起,就會有什麼樣的人生。 和勤奮的人在一起,你不會懶惰; 和積極的人在一起,你不會消沈; 與智者同行,你會不同凡響; 與高人為伍,你能登上巔峰。

    Thursday, December 18, 2014 4:01 PM