เปลี่ยนการวางแนวของการควบคุมผู้ใช้ (ProgressBar) ใน WP7 หรือไม่

ฉันใช้แถบความคืบหน้าในแอปของฉัน แถบความคืบหน้านี้ถูกกำหนดไว้ในการควบคุมผู้ใช้ เช่น:

UserControl x:Class="StirLibrary.ProgressBarControl"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
FontFamily="{StaticResource PhoneFontFamilyNormal}"
FontSize="{StaticResource PhoneFontSizeNormal}"
Foreground="{StaticResource PhoneForegroundBrush}"
mc:Ignorable="d"  d:DesignHeight="800" d:DesignWidth="480">

<Grid x:Name="LayoutRoot" Height="800">
    <Border BorderThickness="2" BorderBrush="Transparent" Background="Transparent" Margin="50,522,50,158">
        <StackPanel>
            <TextBlock Text="Loading..." Name="loading" Grid.Row="1" HorizontalAlignment="Center" Height="30" Foreground="Green">
            </TextBlock>
            <ProgressBar Background="Transparent" Margin="10, 0, 0, 10" Height="80" HorizontalAlignment="Center" Name="progressBar1" VerticalAlignment="Top" Width="380" Grid.Row="2" HorizontalContentAlignment="Left" IsHitTestVisible="True" VerticalContentAlignment="Top" Value="0" Maximum="100">
            </ProgressBar>
        </StackPanel>
    </Border>
</Grid>
</UserControl>

ปัญหาของฉันคือเมื่อการวางแนวของแอปเปลี่ยนเป็นแนวนอน การวางแนวของแถบความคืบหน้าไม่เปลี่ยนแปลง และทำให้แอปดูน่าเกลียด เรายินดีรับข้อเสนอแนะใดๆ เพื่อหลีกเลี่ยงปัญหานี้และทำให้แถบความคืบหน้าแสดงตามการวางแนว


person Apoorva    schedule 18.11.2011    source แหล่งที่มา
comment
คุณแสดงการควบคุมผู้ใช้อย่างไร? หากอยู่ในป๊อปอัป แสดงว่านี่คือปัญหาที่ทราบเกี่ยวกับป๊อปอัป   -  person Matt Lacey    schedule 18.11.2011
comment
ฉันรู้ว่านี่ไม่ได้ตอบคำถามของคุณ แต่บางทีคุณอาจพิจารณาใช้ ProgressIndicator ที่จัดการโดยระบบปฏิบัติการและเป็นมาตรฐานสำหรับการแสดงความคืบหน้า: msdn.microsoft.com/en-us/library/ มิฉะนั้น ฉันจะพิจารณาดู PerformanceProgressBar จาก Silverlight Toolkit ที่คาดว่าจะทำงานได้ดีกว่า ProgressBar นอกกรอบ   -  person Filip Skakun    schedule 18.11.2011
comment
@Matt Am แสดงการควบคุมผู้ใช้ในป๊อปอัป .. และปัญหาของฉันคือโซลูชันทั้งหมดของฉันมีส่วน UI ของโครงการ 3 ส่วนส่วนไลบรารีและส่วนตัวกำหนดเวลา .. และการควบคุมแถบความคืบหน้านี้อยู่ในส่วนของไลบรารีและไม่สามารถเข้าถึงได้ใน ส่วน UI ที่กำลังเรียกเหตุการณ์เพื่อเปลี่ยนการวางแนว .. ฉันรู้วิธีแก้ปัญหาของฉันบางส่วน .. นั่นคือแผงสแต็กที่มีแถบความคืบหน้าจะต้องหมุน 90 องศาและต้องกำหนด (ต้นกำเนิดการแปลงการเรนเดอร์) สำหรับแผงสแต็กเมื่อ การวางแนวเปลี่ยนไปเนื่องจากฉันไม่สามารถเข้าถึงองค์ประกอบแผงสแต็ก ไม่สามารถใช้สิ่งที่ฉันรู้ได้ ..   -  person Apoorva    schedule 21.11.2011


คำตอบ (3)


ตามที่ Matt ได้กล่าวไว้ข้างต้น ไม่สามารถวางแนวป๊อปอัปในการควบคุมผู้ใช้ได้ เนื่องจากการควบคุมผู้ใช้ไม่มีที่ว่างสำหรับการวางแนวที่รองรับ แต่เนื่องจากเป็นข้อกำหนดที่สำคัญมากสำหรับแอปของเรา ฉันจึงพบวิธีแก้ไขและทำการเปลี่ยนแปลงเล็กน้อยในไฟล์คลาสของหน้าหลักและไฟล์คลาสของการควบคุมผู้ใช้ .. การเปลี่ยนแปลงคือ:

 private void PhoneApplicationPage_OrientationChanged(object sender, OrientationChangedEventArgs e)
        {
            if ((e.Orientation & PageOrientation.Portrait) == PageOrientation.Portrait)
            {
ProgressBarControl.getInstance().ProgressBarControl_LayoutUpdated(this, e,e.Orientation.ToString());
}
else if ((e.Orientation & PageOrientation.Landscape) == PageOrientation.Landscape)
            {
ProgressBarControl.getInstance().ProgressBarControl_LayoutUpdated(this, e, e.Orientation.ToString());
}
}

นี่คือการเปลี่ยนแปลงใน MainPage.xaml.cs

public partial class ProgressBarControl : UserControl
{
    private static ProgressBarControl instance = null;
    public static Popup popup;

    private ProgressBarControl()
    {
        InitializeComponent();
    }
    public static ProgressBarControl getInstance()
    {
        if (instance == null)
        {
            instance = new ProgressBarControl();
            popup = new Popup();
            popup.Child = instance;
            popup.IsOpen = false;
        }
        return instance;
    }
    public void ProgressBarControl_LayoutUpdated(object sender, EventArgs e,string orientation)
    {
        if (orientation == "LandscapeRight")
        {
            ProgressPanel.RenderTransformOrigin = new Point(0.5, 0.5);
            ProgressPanel.RenderTransform = new CompositeTransform { Rotation = 270 };
        }
        else if(orientation == "LandscapeLeft")
        {
            ProgressPanel.RenderTransformOrigin = new Point(0.5, 0.5);
            ProgressPanel.RenderTransform = new CompositeTransform { Rotation = 90 };
        }
        else
        {
            ProgressPanel.RenderTransformOrigin = new Point(0, 0);
            ProgressPanel.RenderTransform = new CompositeTransform { Rotation = 0 };
        }

    }

    public static void displayProgressBar(int requestId, int status, string msg)
    {
        System.Windows.Deployment.Current.Dispatcher.BeginInvoke(() =>
            {
                if (instance == null)
                {
                    instance = new ProgressBarControl();
                    popup = new Popup();
                    popup.Child = instance;
                }
                popup.IsOpen = true;
                instance.loading.Text = msg;
                instance.progressBar1.IsIndeterminate = true;
                instance.progressBar1.Value = status;
            });
    }
    public static void dismissProgressBar()
    {
        System.Windows.Deployment.Current.Dispatcher.BeginInvoke(() =>
            {
                if(popup!=null)
                {
                    popup.IsOpen = false;
                }
            });
    }
}

และนี่คือสิ่งที่ฉันทำในไฟล์ ProgressBarControl.cs ของฉัน (นี่คือไฟล์คลาสของการควบคุมผู้ใช้)

ไฟล์ Xaml:

<UserControl x:Class="StirLibrary.ProgressBarControl"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
FontFamily="{StaticResource PhoneFontFamilyNormal}"
FontSize="{StaticResource PhoneFontSizeNormal}"
Foreground="{StaticResource PhoneForegroundBrush}"
mc:Ignorable="d"  d:DesignHeight="800" d:DesignWidth="480">

<Grid x:Name="LayoutRoot" Height="800">
    <!--<Border BorderThickness="2" BorderBrush="Black" Background="Transparent" Margin="54,406,50,320"></Border>-->
    <StackPanel x:Name="ProgressPanel" Background="Black" Margin="54,406,50,320">
        <TextBlock Text="Loading..." Name="loading" Grid.Row="1" HorizontalAlignment="Center" Height="32" Foreground="White"></TextBlock>
        <ProgressBar Background="Green" Margin="10, 0, 0, 10" Height="33" Foreground="White" HorizontalAlignment="Center" Name="progressBar1" VerticalAlignment="Top" Width="351" Grid.Row="2" HorizontalContentAlignment="Left" IsHitTestVisible="True" VerticalContentAlignment="Top" Value="0" Maximum="100"></ProgressBar>
    </StackPanel>
</Grid>
</UserControl>
person Apoorva    schedule 24.11.2011

ฉันสามารถเปิดใช้งานการวางแนวสำหรับป๊อปอัป UserControl ของฉันได้โดยเพียงแค่เพิ่มลูก ๆ ของหน้าจอหลักซึ่งป๊อปอัปจะแสดงเป็น:

popUp = new Popup();
loginControl = new LoginPopup();  // this is the custom UserControl

popUp.Child = loginControl;
LayoutRoot.Children.Add(popUp);
person Jalpa    schedule 08.05.2012

Popup< /a> คลาสไม่รองรับการวางแนว ดังนั้นคุณจึงไม่สามารถใช้สิ่งนี้ได้และคาดว่าจะรองรับการเปลี่ยนแปลงการวางแนว โดยไม่คำนึงว่าตัวควบคุมที่แสดงในป๊อปอัปอยู่ในแอสเซมบลีเดียวกันหรือไม่

แทนที่จะใช้ Popup ทางเลือกง่ายๆ คือการวางตัวควบคุมไว้เหนือเนื้อหาอื่นๆ ทั้งหมดในเพจโดยตรง คุณสามารถรวมสิ่งนี้ไว้ในการควบคุมอื่น (เช่น ตารางหรือแผง) ได้ หากต้องการ

การเพิ่ม RotateTransform ให้กับส่วนควบคุมด้วยตนเองจะทำให้คุณสามารถเพิ่มการควบคุมพิเศษในการปรับการวางแนวได้ แต่ฉันขอแนะนำว่าอย่าไปตามเส้นทางนี้หากคุณสามารถหลีกเลี่ยงได้

person Matt Lacey    schedule 21.11.2011
comment
ฉันพบเคล็ดลับในการทำ :) และการปฐมนิเทศทำงานได้ดี .. จะโพสต์คำตอบเร็ว ๆ นี้ - person Apoorva; 24.11.2011