Skip to content

Commit 2e8430d

Browse files
committed
WPF wip (very old)
1 parent b764d0f commit 2e8430d

File tree

3 files changed

+35
-9
lines changed

3 files changed

+35
-9
lines changed

src/CSharpMarkup.Wpf.Examples/SearchPage.logic.cs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,21 @@ internal sealed partial class SearchPage : BasePage, IBuild
2020

2121
public SearchPage()
2222
{
23+
this.Initialized += OnInitialized;
2324
DataContext = vm = App.Current!.SearchViewModel;
2425
Build();
2526
}
2627

28+
protected override void OnInitialized(EventArgs e)
29+
{
30+
base.OnInitialized(e);
31+
}
32+
33+
void OnInitialized(object? sender, EventArgs e)
34+
{
35+
36+
}
37+
2738
static BitmapImage UriImage(string uri)
2839
{
2940
BitmapImage bitmap = new BitmapImage();

src/CSharpMarkup.Wpf/CSharpMarkup.Wpf.csproj

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -44,15 +44,6 @@
4444
<EmbedUntrackedSources>true</EmbedUntrackedSources>
4545
</PropertyGroup>
4646

47-
<PropertyGroup Condition=" '$(Configuration)' == 'Generate' ">
48-
<EmitCompilerGeneratedFiles>true</EmitCompilerGeneratedFiles>
49-
<CompilerGeneratedFilesOutputPath>Generated</CompilerGeneratedFilesOutputPath>
50-
</PropertyGroup>
51-
52-
<ItemGroup Condition=" '$(Configuration)' == 'Generate' ">
53-
<Compile Remove="$(CompilerGeneratedFilesOutputPath)/*/**/*.cs" />
54-
</ItemGroup>
55-
5647
<ItemGroup>
5748
<PackageReference Include="Microsoft.SourceLink.GitHub" PrivateAssets="All" />
5849
</ItemGroup>

src/CSharpMarkup.Wpf/DependencyObject.cs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -507,6 +507,30 @@ public static TDependencyObject BindCommandWithString<TDependencyObject>(
507507
return target;
508508
}
509509

510+
public static TDependencyObject StaticResource<TDependencyObject, TPropertyValue>(
511+
this DependencyProperty<TDependencyObject, TPropertyValue> property,
512+
System.Windows.FrameworkElement element,
513+
string key
514+
) where TDependencyObject : DependencyObject
515+
=> property.Set((TPropertyValue)element.FindResource(key));
516+
// TODO: need to set e.g. page resources in C# from either XAML or C#, before Build() is invoked -
517+
// but then why use a resource? we can use named static fields. Unless we want to reuse an app level xaml resource
518+
519+
public static TDependencyObject DynamicResource<TDependencyObject, TPropertyValue>(
520+
this DependencyProperty<TDependencyObject, TPropertyValue> property,
521+
System.Windows.FrameworkElement element,
522+
string key
523+
) where TDependencyObject : DependencyObject
524+
{ element.SetResourceReference(property.UI, key); return property.Target; }
525+
// TODO: verify this will work for resources added in the parents after reparenting and after updating the parent resources
526+
527+
// Correct order: do the resource lookups after OnInitalized is called on the page
528+
// 1) Content attaches onitialised event handler.
529+
530+
// Purpose of resource dictionaries:
531+
// - reuse of XAML resources in C# page => application resources => (cast)Application.Current.Resources["key"]
532+
// ? reuse of C# in XAML page?
533+
510534
public static TDependencyObject Assign<TDependencyObject, TUI>(this TDependencyObject bindable, out TUI ui)
511535
where TDependencyObject : DependencyObject, IUI<TUI>
512536
where TUI : System.Windows.DependencyObject

0 commit comments

Comments
 (0)