private string _unrealizedPnL;
public string UnrealizedPnL
{
get { return _unrealizedPnL; }
set
{
if (_unrealizedPnL != value)
{
_unrealizedPnL = value;
OnPropertyChanged();
if (pnLTextBlock2 != null)
{UpdateTextBlockStyles();}
}
}
}
private string _realizedPnL;
public string RealizedPnL
{
get { return _realizedPnL; }
set
{
if (_realizedPnL != value)
{
_realizedPnL = value;
OnPropertyChanged();
if (pnLTextBlock2 != null)
{UpdateTextBlockStyles();}
}
}
}
private string _totalPnL;
public string TotalPnL
{
get { return _totalPnL; }
set
{
if (_totalPnL != value)
{
_totalPnL = value;
OnPropertyChanged();
if (pnLTextBlock1 != null)
{UpdateTextBlockStyles();}
}
}
}
private string _netLiq;
public string NetLiq
{
get { return _netLiq; }
set
{
if (_netLiq != value)
{
_netLiq = value;
OnPropertyChanged();
if (pnLTextBlock1 != null)
{UpdateTextBlockStyles();}
}
}
}
public event PropertyChangedEventHandler PropertyChanged;
protected virtual void OnPropertyChanged([CallerMemberName] string propertyName = null)
{
var handler = PropertyChanged;
if (handler != null)
{
handler(this, new PropertyChangedEventArgs(propertyName));
}
}
private void UpdateTextBlockStyles()
{
ChartControl.Dispatcher.InvokeAsync(() =>
{
double netLiqValue, realizedPnLValue, unrealizedPnLValue, totalPnLValue;
double.TryParse(NetLiq, out netLiqValue);
double.TryParse(RealizedPnL, out realizedPnLValue);
double.TryParse(UnrealizedPnL, out unrealizedPnLValue);
double.TryParse(TotalPnL, out totalPnLValue);
if (pnLTextBlock1 != null)
{
pnLTextBlock1.Inlines.Clear();
pnLTextBlock1.Inlines.Add(new Run("Net Liquidation: ") { Foreground = Application.Current.FindResource("ChartControl.Cha rtText") as Brush });
var netLiqRun = new Run(netLiqValue.ToString("C", CultureInfo.CurrentCulture)) { Foreground = netLiqValue >= 0 ? Brushes.Lime : Brushes.Red };
pnLTextBlock1.Inlines.Add(netLiqRun);
pnLTextBlock1.Inlines.Add(new Run(" Total P&L: ") { Foreground = Application.Current.FindResource("ChartControl.Cha rtText") as Brush });
var totalPnLRun = new Run(totalPnLValue.ToString("C", CultureInfo.CurrentCulture)) { Foreground = totalPnLValue >= 0 ? Brushes.Lime : Brushes.Red };
pnLTextBlock1.Inlines.Add(totalPnLRun);
}
if (pnLTextBlock2 != null)
{
pnLTextBlock2.Inlines.Clear();
pnLTextBlock2.Inlines.Add(new Run("Realized P&L: ") { Foreground = Application.Current.FindResource("ChartControl.Cha rtText") as Brush });
var realizedPnLRun = new Run(realizedPnLValue.ToString("C", CultureInfo.CurrentCulture)) { Foreground = realizedPnLValue >= 0 ? Brushes.Lime : Brushes.Red };
pnLTextBlock2.Inlines.Add(realizedPnLRun);
pnLTextBlock2.Inlines.Add(new Run(" Unrealized P&L: ") { Foreground = Application.Current.FindResource("ChartControl.Cha rtText") as Brush });
var unrealizedPnLRun = new Run(unrealizedPnLValue.ToString("C", CultureInfo.CurrentCulture)) { Foreground = unrealizedPnLValue >= 0 ? Brushes.Lime : Brushes.Red };
pnLTextBlock2.Inlines.Add(unrealizedPnLRun);
}
});
}
// Assuming 'this' is the DataContext that contains the properties you want to bind to
myGrid2.DataContext = this;
// Bind the Text property of pnLTextBlock1 to NetLiq
pnLTextBlock1 = new TextBlock
{
Name = "pnLTextBlock1",
// Foreground = Brushes.White,
Background = Brushes.Transparent,
HorizontalAlignment = HorizontalAlignment.Left,
VerticalAlignment = VerticalAlignment.Center,
FontSize = 12,
};
Binding netLiqBinding = new Binding("NetLiq")
{
Source = this, // Ensure this is the object where NetLiq property is defined
};
pnLTextBlock1.SetBinding(TextBlock.TextProperty, netLiqBinding);
// Bind the Text property of pnLTextBlock2 to RealizedPnL
pnLTextBlock2 = new TextBlock
{
Name = "pnLTextBlock2",
// Foreground = Brushes.White,
Background = Brushes.Transparent,
HorizontalAlignment = HorizontalAlignment.Left,
VerticalAlignment = VerticalAlignment.Center,
FontSize = 12,
};
Binding realizedPnLBinding = new Binding("RealizedPnL")
{
Source = this, // Ensure this is the object where RealizedPnL property is defined
};
pnLTextBlock2.SetBinding(TextBlock.TextProperty, realizedPnLBinding);
Comment