Bei "Always On Top" muss man entweder periodisch oder eventbasiert (so machen das die PowerToys) immer wieder überprüfen, ob das was "Always On Top" sein soll auch immer noch "On Top" ist und wenn nicht, dann eben wieder dort hinbringen.
Hast du dir schon mal UI.SyntaxBox angeschaut?
Ja, das ist eine TextBox
aber es geht eher um das Prinzip, wie die das da machen. Da wird auf jeden Fall das Binding überhaupt nicht gestört.
Das wäre eine Möglichkeit
<Window
x:Class="WpfApp1.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:WpfApp1"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:sys="clr-namespace:System;assembly=mscorlib"
Title="MainWindow"
Width="800"
Height="450"
d:DataContext="{d:DesignData IsDesignTimeCreatable=False,
Type={x:Type local:MainWindowModel}}"
mc:Ignorable="d">
<Window.DataContext>
<local:MainWindowModel />
</Window.DataContext>
<Window.Resources>
<ObjectDataProvider
x:Key="Difficulties"
MethodName="GetValues"
ObjectType="{x:Type sys:Enum}">
<ObjectDataProvider.MethodParameters>
<x:Type TypeName="local:Difficulty" />
</ObjectDataProvider.MethodParameters>
</ObjectDataProvider>
</Window.Resources>
<DockPanel>
<StackPanel DockPanel.Dock="Top">
<ListBox ItemsSource="{Binding Source={StaticResource Difficulties}}" SelectedItem="{Binding SelectedDifficulty}">
<ListBox.ItemContainerStyle>
<Style TargetType="{x:Type ListBoxItem}">
<Setter Property="Padding" Value="0" />
<Setter Property="Margin" Value="0" />
<Setter Property="Focusable" Value="False" />
</Style>
</ListBox.ItemContainerStyle>
<ListBox.ItemsPanel>
<ItemsPanelTemplate>
<StackPanel Orientation="Horizontal" />
</ItemsPanelTemplate>
</ListBox.ItemsPanel>
<ListBox.ItemTemplate>
<DataTemplate>
<Button
MinWidth="80"
Margin="0"
Padding="5,2"
Command="{Binding DataContext.SelectDifficultyCommand, RelativeSource={RelativeSource AncestorType=ListBox}}"
CommandParameter="{Binding}"
Content="{Binding}">
<Button.Style>
<Style TargetType="{x:Type Button}">
<Style.Triggers>
<DataTrigger Binding="{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type ListBoxItem}}, Path=IsSelected}" Value="True">
<Setter Property="Background" Value="Red" />
<Setter Property="Foreground" Value="White" />
<Setter Property="IsHitTestVisible" Value="False" />
</DataTrigger>
</Style.Triggers>
</Style>
</Button.Style>
</Button>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
</StackPanel>
<Grid />
</DockPanel>
</Window>
public enum Difficulty
{
Easy,
Medium,
Hard
}
public class MainWindowModel : ReactiveObject
{
[Reactive]
public Difficulty SelectedDifficulty { get; set; }
public ReactiveCommand<Difficulty, Unit> SelectDifficultyCommand { get; }
public MainWindowModel()
{
SelectDifficultyCommand = ReactiveCommand.Create<Difficulty>( SelectDifficultyCommandExecute );
}
private void SelectDifficultyCommandExecute( Difficulty d )
{
SelectedDifficulty = d;
}
}
Möglicherweise ist aber auch der ToggleButton
etwas für dich
<ListBox ItemsSource="{Binding Source={StaticResource Difficulties}}"
SelectedItem="{Binding SelectedDifficulty}">
<ListBox.ItemContainerStyle>
<Style TargetType="{x:Type ListBoxItem}">
<Setter Property="Padding"
Value="0" />
<Setter Property="Margin"
Value="0" />
<Setter Property="Focusable"
Value="False" />
</Style>
</ListBox.ItemContainerStyle>
<ListBox.ItemsPanel>
<ItemsPanelTemplate>
<StackPanel Orientation="Horizontal" />
</ItemsPanelTemplate>
</ListBox.ItemsPanel>
<ListBox.ItemTemplate>
<DataTemplate>
<ToggleButton MinWidth="80"
Margin="0"
Padding="5,2"
Content="{Binding}"
IsChecked="{Binding IsSelected, RelativeSource={RelativeSource AncestorType=ListBoxItem}}" />
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
Ich habe da mal etwas vorbereitet und das funktioniert wunderbar
public partial class Form1 : Form
{
private readonly Random random = new Random();
public Form1()
{
InitializeComponent();
}
private Data GetRandomData()
{
return new Data
{
Name = "Daten",
Title = "Kurs",
Label = "Kurs",
DataPoints = Enumerable
.Range( 1, 31 )
.Select( x => new DataPoint { Date = new DateTime( 2025, 1, x ), Value = random.Next( 250 ) } )
.ToList()
.AsReadOnly(),
};
}
private void button1_Click( object sender, EventArgs e )
{
var data = GetRandomData();
chart1.SetData( data );
}
}
public static class ChartExtensions
{
public static Chart SetData( this Chart chart, Data data )
{
chart.Series.Clear();
chart.Series.AddData( data );
chart.ChartAreas.Clear();
chart.ChartAreas.AddData( data );
chart.Titles.Clear();
var title = chart.Titles.Add( data.Title );
title.Font = new System.Drawing.Font( "Arial", 16, FontStyle.Bold );
return chart;
}
public static Series AddData( this SeriesCollection collection, Data data )
{
Series series = new Series();
series.Name = data.Name;
series.ChartType = SeriesChartType.Column;
series.XValueType = ChartValueType.DateTime;
series.YValueType = ChartValueType.Auto;
data.DataPoints.ToList().ForEach( x => series.Points.AddXY( x.Date, x.Value ) );
collection.Add( series );
return series;
}
public static ChartArea AddData( this ChartAreaCollection collection, Data data )
{
var area = new ChartArea();
area.AxisX.Title = "Datum";
area.AxisY.Title = data.Label;
collection.Add( area );
return area;
}
}
public class Data
{
public string Title { get; set; }
public string Name { get; set; }
public string Label { get; set; }
public IReadOnlyCollection<DataPoint> DataPoints { get; set; }
}
public class DataPoint
{
public DateTime Date { get; set; }
public decimal Value { get; set; }
}
Also hiermit
public class SomeController : ControllerBase
{
[HttpPost( Name = "SetData" )]
public IActionResult Post( [FromBody] Data model )
{
return Ok();
}
}
public class Data
{
[Required]
public Guid? RetailerId { get; set; }
[Required]
public string? Name { get; set; }
}
public class ValidateModelAttribute : ActionFilterAttribute
{
public override void OnActionExecuting( ActionExecutingContext actionContext )
{
if ( actionContext.ModelState.IsValid == false )
{
actionContext.Result = new BadRequestObjectResult( actionContext.ModelState );
}
}
}
// Add services to the container.
builder.Services.AddControllers( options =>
{
options.Filters.Add<ValidateModelAttribute>();
} );
erhalte ich bei dem Aufruf
POST {{MyWebApi_HostAddress}}/some/
Content-Type: application/json
Accept: application/json
{
"retailerId": null,
"name": null
}
diesen response
HTTP/1.1 400 Bad Request
Connection: close
Content-Type: application/problem+json; charset=utf-8
Date: Wed, 29 Jan 2025 09:25:58 GMT
Server: Kestrel
Transfer-Encoding: chunked
{
"type": "https://tools.ietf.org/html/rfc9110#section-15.5.1",
"title": "One or more validation errors occurred.",
"status": 400,
"errors": {
"Name": [
"The Name field is required."
],
"RetailerId": [
"The RetailerId field is required."
]
},
"traceId": "00-5d5349a341853bf4ad3939fc19697e5b-0fbb3215c4907859-00"
}
Ist das nicht das was du suchst?
Dabei stelle ich fest, dass der Filter dafür gar nicht gebraucht wird.
Mach deine Seite mal ein klein wenig höher (so 760 Pixel) und dann schau mal genau hin 😃
Nur so zur Info, aber diese Zeile Code hier
this.DataContext = DataContext;
kannst du ersatzlos streichen. Du weist der Eigenschaft DataContext
den Wert der Eigenschaft DataContext
zu. Bildlich gesprochen nimmst du den 5-EUR-Schein aus deinem Portmonee und steckst diesen 5-EUR-Schein wieder dorthin zurück.
Zitat von Tom3419
Oder wo ist der Denkfehler?
Wenn du immer die GLEICHEN Werte bei der Form setzt, warum sollte die Form an einer anderen Stelle erscheinen?
Dieser Code
Screen monitor = Screen.AllScreens[screenIdx];
holt nur einen Wert aus einer Auflistung. Punkt. Mehr macht er nicht. Er stellet nichts irgenwie wo ein!
Der Code, der das was du möchtest macht, den habe ich schon hier gezeigt. Also ist es eher ein Lese- als ein Denkfehler