바이너리 시계를 만들려고하는데 제대로 작동합니다.Silverlight, img 소스를 변경하여 gui 업데이트 C#
다음과 같이 작동합니다.
run이라는 메서드를 호출 할 때마다 시간이 설정되고 일부 img 소스가 변경됩니다 (img은 내 램프이고, img 소스는 꺼지거나 켜질 때마다 변경됩니다).
하지만 어떻게 항상 실행시킬 수 있습니까?
루프를 만들면 모바일에서 시작하지 않으며 스레딩을 사용하면 아무 것도하지 않는 것과 같습니다.
일부 속성을 변경 한 후에 GUI를 업데이트 할 수있는 방법이 있습니까?
XMAL 코드
<phone:PhoneApplicationPage
x:Class="BinSample.MainPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:phone="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone"
xmlns:shell="clr-namespace:Microsoft.Phone.Shell;assembly=Microsoft.Phone"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d" d:DesignWidth="480" d:DesignHeight="768"
FontFamily="{StaticResource PhoneFontFamilyNormal}"
FontSize="{StaticResource PhoneFontSizeNormal}"
Foreground="{StaticResource PhoneForegroundBrush}"
SupportedOrientations="Portrait" Orientation="Portrait"
shell:SystemTray.IsVisible="True">
<!--LayoutRoot is the root grid where all page content is placed-->
<Grid x:Name="LayoutRoot" Background="Transparent">
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<!--TitlePanel contains the name of the application and page title-->
<StackPanel x:Name="TitlePanel" Grid.Row="0" Margin="12,17,0,28">
<TextBlock x:Name="ApplicationTitle" Text="MY APPLICATION" Style="{StaticResource PhoneTextNormalStyle}"/>
<TextBlock x:Name="PageTitle" Text="page name" Margin="9,-7,0,0" Style="{StaticResource PhoneTextTitle1Style}"/>
</StackPanel>
<!--ContentPanel - place additional content here-->
<Grid x:Name="ContentPanel" Grid.Row="1" Margin="12,0,12,0">
<Image Height="80" HorizontalAlignment="Left" Margin="141,187,0,0" Name="imag1" Stretch="Fill" VerticalAlignment="Top" Width="106" Source="/BinSample;component/img/knapSluk.png" />
</Grid>
</Grid>
public MainPage()
{
InitializeComponent();
//test one
//try to make a neverending loop
Run();
//testc two
//try loop with thread an sleep funtion.
thredRun();
}
public void thredRun()
{
new Thread(new ThreadStart(thredRun));
while (true)
{
Run();
Thread.Sleep(100);
}
}
public void Run()
{
while (true)
{
int hour = DateTime.Now.Hour;
if (hour % 10 == 0)
imag1.Source = new BitmapImage(new Uri("img/knapTaand.png", UriKind.Relative));
else
imag1.Source = new BitmapImage(new Uri("img/knapSluk.png", UriKind.Relative));
}
}
}
당신이 지금까지 작업 한 내용의 샘플을 게시 할 수 루프의하지 않는 사용하는 것입니다 작업? 이 '와 같은 당신이 원한다면 내 projct를 압축하여 업로드 할 수 있습니다 @SilverSolver –
, 다른 의 일 동안 (진짜야) { img.Source = 새로운 BitmapImage (statemant가 true) 경우 (새 열린 우리당 (" img/knapSluk.png ", UriKind.Relative)); else imgHour1.Source = 새 BitmapImage (새 Uri ("img/knapTaand.png", UriKind.Relative)); } ' – DaCh
btw, stackoverflow에 처음으로 아무것도 게시하지 않으므로 코드의 일부를 지나치는 것과 같은 모든 일을 실제로하지는 않습니다. – DaCh