the promise of a result in the future
In general, I'd recommend that you use the higher level abstraction wherever you can: in modern C# code you should rarely need to explicitly start your own thread.
Why we need Tasks
It can be used whenever you want to execute something in parallel. Asynchronous implementation is easy in a task, using’ async’ and ‘await’ keywords.
Why we need a Thread
When the time comes when the application is required to perform few tasks at the same time.
Explicit is better than implicit.
public partial class MainWindow : Window
{
BigWindow bigWindow = new BigWindow();
SmallWindow smallWindow = new SmallWindow();
public View _view = new View();
public MainWindow()
{
//some code
DataContext = _view;
bigWindow.DataContext = DataContext;
//some code
public partial class BigWindow : Window
{
public BigWindow()
{
InitializeComponent();
SetStyles(); //пробуем поменать стили
}
<Style x:Key="NumbersStyle">
<Setter Property="Control.Foreground" Value="{Binding Path=BigWindowColors.ColorNumbers, TargetNullValue=white}"/>
</Style>
<Window.Resources>
<Style x:Key="BaseFontFamily">
<!-- Базовый стиль с цветом-->
<Setter Property="Control.Foreground" Value="#FF4500"/>
</Style>
<Style x:Key="NumbersStyle" TargetType="TextBlock" BasedOn="{StaticResource BaseFontFamily}">
<Setter Property="Control.FontSize" Value="50"/>
<Setter Property="Control.Background" Value="Transparent"/>
<Setter Property="Control.HorizontalContentAlignment" Value="Center"/>
<Setter Property="Control.VerticalContentAlignment" Value="Center"/>
<Setter Property="Control.HorizontalAlignment" Value="Stretch"/>
<Setter Property="Control.VerticalAlignment" Value="Stretch"/>
</Style>
<!-- Еще стили с наследованием BaseFontFamily-->
</Window.Resources>
public void SetStyles()
{
Setter setter = new Setter(ForegroundProperty, Color.FromArgb(0, 0, 0, 0));
Style = Resources["NumbersStyle"] as Style;
Style.Setters.Add(setter);
}
<Style x:Key="NumbersStyle" BasedOn="{StaticResource BaseFontFamily}">
<Style x:Key="NumbersStyle" TargetType="TextBlock" BasedOn="{StaticResource BaseFontFamily}">
public void SetStyles()
{
Setter setter = new Setter(ForegroundProperty, Color.FromArgb(0, 0, 0, 0));
Style = Resources["NumbersStyle"] as Style;
Style.Setters.Add(setter);
}
private short _TeamCounter;//счетчик очков команды
public short TeamCounter { get => _TeamCounter;
set
{
_TeamCounter = value;
OnPropertyChanged("TeamCounter");
}
}
public event PropertyChangedEventHandler PropertyChanged;
public void OnPropertyChanged( [CallerMemberName] string prop = "")
{
if (PropertyChanged != null)
PropertyChanged(this, new PropertyChangedEventArgs(prop));
}