WPF [调用线程无法访问此对象,因为另一个线程拥有该对象。] 解决方案以及如何实现字体颜色的渐变...
生活随笔
收集整理的這篇文章主要介紹了
WPF [调用线程无法访问此对象,因为另一个线程拥有该对象。] 解决方案以及如何实现字体颜色的渐变...
小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
為什么80%的碼農(nóng)都做不了架構(gòu)師?>>> ??
<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="不問(wèn)你是誰(shuí)只是沉醉!" 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);//實(shí)例化Timer類,設(shè)置間隔時(shí)間為200毫秒; t.Elapsed += new System.Timers.ElapsedEventHandler(theout); //到達(dá)時(shí)間的時(shí)候執(zhí)行事件; t.AutoReset = true;//設(shè)置是執(zhí)行一次(false)還是一直執(zhí)行(true); t.Enabled = true; //是否執(zhí)行System.Timers.Timer.Elapsed事件; ,調(diào)用start()方法也可以將其設(shè)置為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;}})); }
轉(zhuǎn)載于:https://my.oschina.net/wange/blog/111424
總結(jié)
以上是生活随笔為你收集整理的WPF [调用线程无法访问此对象,因为另一个线程拥有该对象。] 解决方案以及如何实现字体颜色的渐变...的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: 页面用ajax实现简单的连接数据库
- 下一篇: TX Text Control文字处理教