WPF [调用线程无法访问此对象,因为另一个线程拥有该对象。] 解决方案以及如何实现字体颜色的渐变...
生活随笔
收集整理的這篇文章主要介紹了
WPF [调用线程无法访问此对象,因为另一个线程拥有该对象。] 解决方案以及如何实现字体颜色的渐变...
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
為什么80%的碼農都做不了架構師?>>> ??
<Window x:Class="MyWPFApp.MainWindow"xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"Title="MainWindow" Height="70" Width="250" Loaded="Window_Loaded"><Grid><TextBlock Height="36" HorizontalAlignment="Left" Name="gc" Text="不問你是誰只是沉醉!" VerticalAlignment="Top" Width="230" FontSize="24"><TextBlock.Foreground><LinearGradientBrush> <GradientStop Color="Green"></GradientStop><GradientStop x:Name="gcc1" Color="Green" Offset="0.3"></GradientStop><GradientStop x:Name="gcc2" Color="Blue" Offset="0.3"></GradientStop><GradientStop Color="Blue" Offset="1"></GradientStop> </LinearGradientBrush></TextBlock.Foreground></TextBlock></Grid> </Window> using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Windows; using System.Windows.Controls; using System.Windows.Data; using System.Windows.Documents; using System.Windows.Input; using System.Windows.Media; using System.Windows.Media.Imaging; using System.Windows.Navigation; using System.Windows.Shapes; namespace MyWPFApp {/// <summary>/// MainWindow.xaml 的交互邏輯/// </summary>public partial class MainWindow : Window{public MainWindow(){InitializeComponent();}private void Window_Loaded(object sender, RoutedEventArgs e){System.Timers.Timer t = new System.Timers.Timer(200);//實例化Timer類,設置間隔時間為200毫秒; t.Elapsed += new System.Timers.ElapsedEventHandler(theout); //到達時間的時候執行事件; t.AutoReset = true;//設置是執行一次(false)還是一直執行(true); t.Enabled = true; //是否執行System.Timers.Timer.Elapsed事件; ,調用start()方法也可以將其設置為true }public void theout(object source, System.Timers.ElapsedEventArgs e){ }} } 委托的使用
public void theout(object source, System.Timers.ElapsedEventArgs e){this.gcc1.Dispatcher.Invoke(new Action(delegate{if (this.gcc1.Offset < 1){this.gcc1.Offset += 0.1;}else{this.gcc1.Offset = 0;}}));this.gcc2.Dispatcher.Invoke(new Action(delegate{if (this.gcc2.Offset < 1){this.gcc2.Offset += 0.1;}else{this.gcc2.Offset = 0;}})); }
轉載于:https://my.oschina.net/wange/blog/111424
總結
以上是生活随笔為你收集整理的WPF [调用线程无法访问此对象,因为另一个线程拥有该对象。] 解决方案以及如何实现字体颜色的渐变...的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 页面用ajax实现简单的连接数据库
- 下一篇: TX Text Control文字处理教