尝试使用uwp中的forloop点击箭头来更改图像和文本

时间:2016-11-24 15:14:01

标签: c# xaml uwp

我试图在uwp中使用forloop点击箭头来更改图像和文字。 图像存储在解决方案资源管理器中的Assets文件夹中,我也想要更改" HeaderName" &安培; " objNameWritten"点击按钮后的属性,但没有任何想法。任何帮助将不胜感激。

Xaml代码:

<Grid Name="L_Col_View">
        <Grid.Background>
            <ImageBrush  ImageSource="Assets/LearnColor/bg.png"/>
        </Grid.Background>        
        <Image x:Name="imgContainer"
            Source="Assets/LearnColor/ob_bg.png"              
               Height="240" Width="300"/>
        <Image x:Name="image"
            Source="Assets/LearnColor/Object/ob_gray_1.png"              
               Height="190" Width="290"
               VerticalAlignment="Center"
               />
        <Grid>
            <Image x:Name="Header" 
            Source="Assets/LearnColor/Header/_0007_header_gray.png"              
               Height="100" Width="330"
               VerticalAlignment="Top"
               Margin="0,20,0,0"               
               />
            <TextBlock x:Name="HeaderName"
                Text="Grey"
               VerticalAlignment="Top"
               Margin="290,20,0,0" FontSize="30" FontStyle="Normal" FontWeight="ExtraBold" />
        </Grid>
        <Grid>
            <Image x:Name="objName" 
            Source="Assets/LearnColor/object_name_bg.png"              
               Height="100" Width="280"
               VerticalAlignment="Bottom"
               Margin="0,0,0,30"/>
            <TextBlock x:Name="objNameWritten"
                Text="Elephant"
               VerticalAlignment="Bottom"
               Margin="260,0,0,30" FontSize="30" FontStyle="Normal" FontWeight="ExtraBold" />
        </Grid>

        <Image x:Name="prevBtn" 
            Source="Assets/LearnColor/Button/btn_previous_arrow.png"              
               Height="90" Width="100"
               VerticalAlignment="Top"
               HorizontalAlignment="Left"
               Margin="60,10,0,0"
               Tapped="BckImgChng"/>
        <Image x:Name="FwdBtn"
            Source="Assets/LearnColor/Button/btn_next_arrow.png"              
               Height="90" Width="100"
               VerticalAlignment="Top"
               HorizontalAlignment="Right"
               Margin="0,10,60,0"
               Tapped="FwdImgChng"/>        
        <Image x:Name="prevObjBtn"
            Source="Assets/LearnColor/Button/_0004_previous-copy-5.png"              
               Height="90" Width="80"
               VerticalAlignment="Center"
               HorizontalAlignment="Left"
               Margin="80,10,0,0"/>
        <Image x:Name="fwdObjBtn"
            Source="Assets/LearnColor/Button/_0005_next-copy-5.png"              
               Height="90" Width="80"
               VerticalAlignment="Center"
               HorizontalAlignment="Right"
               Margin="0,10,80,0"/>
        <Image x:Name="homeBtn"
            Source="Assets/LearnColor/Button/btn_home.png"              
               Height="90" Width="80"
               VerticalAlignment="Center"
               HorizontalAlignment="Left"
               Margin="20,140,0,0"/>
        <Image x:Name="volBtn"
            Source="Assets/LearnColor/Button/btn_sound.png"              
               Height="90" Width="80"
               VerticalAlignment="Bottom"
               HorizontalAlignment="Left"
               Margin="20,0,0,15"/>
    </Grid>

.cs代码:

公共密封的分类L_Col_Act:Page {

public class MyImage
{
    public string Header { get; set; }
    public string image { get; set; }
    public string prevObjBtn { get; set; }
    public string fwdObjBtn { get; set; }
    public string HeaderName { get; set; }
    public string objNameWritten { get; set; }

}
string[] Headername = new string[] { "Yellow", "white", "red","purple","pink","orange","green","grey","brown","blue","black"};
string[] objnamewritten = new string[] { "Banana", "Sheep", "Berry", "Grapes", "Icecream", "Girrafe", "Tree", "Elephant", "Log", "Sky", "Crow" };

public L_Col_Act()
{
    this.InitializeComponent();           


}
//private int count = -1;
int currentIndex = 0;

//pariwesh
private void FwdImgChng(object sender, TappedRoutedEventArgs e)
{
    if (currentIndex == 11)
        currentIndex = 0;
    Header.Source = new BitmapImage(new Uri("ms-appx:///Assets/LearnColor/Header/_0000_header_" + currentIndex + ".png"));
    image.Source = new BitmapImage(new Uri("ms-appx:///Assets/LearnColor/Object/ob_" + currentIndex + "_1.png"));
    prevObjBtn.Source = new BitmapImage(new Uri("ms-appx:///Assets/LearnColor/Button/prev" + currentIndex + ".png"));
    fwdObjBtn.Source = new BitmapImage(new Uri("ms-appx:///Assets/LearnColor/Button/next" + currentIndex + ".png"));
    HeaderName.Text = Headername[currentIndex];
    objNameWritten.Text = objnamewritten[currentIndex];
    mediaElement1.Source = new Uri("ms-appx:///Assets/LearnColor/Objectnamesmp3/" + currentIndex + "_1.mp3");
    mediaElement1.AutoPlay = true;
    currentIndex++;

}

0 个答案:

没有答案