|
Apologies for the shouting but this is important.
When answering a question please:
- Read the question carefully
- Understand that English isn't everyone's first language so be lenient of bad spelling and grammar
- If a question is poorly phrased then either ask for clarification, ignore it, or mark it down. Insults are not welcome
- If the question is inappropriate then click the 'vote to remove message' button
Insults, slap-downs and sarcasm aren't welcome. Let's work to help developers, not make them feel stupid.
cheers,
Chris Maunder
The Code Project Co-founder
Microsoft C++ MVP
|
|
|
|
|
For those new to message boards please try to follow a few simple rules when posting your question.- Choose the correct forum for your message. Posting a VB.NET question in the C++ forum will end in tears.
- Be specific! Don't ask "can someone send me the code to create an application that does 'X'. Pinpoint exactly what it is you need help with.
- Keep the subject line brief, but descriptive. eg "File Serialization problem"
- Keep the question as brief as possible. If you have to include code, include the smallest snippet of code you can.
- Be careful when including code that you haven't made a typo. Typing mistakes can become the focal point instead of the actual question you asked.
- Do not remove or empty a message if others have replied. Keep the thread intact and available for others to search and read. If your problem was answered then edit your message and add "[Solved]" to the subject line of the original post, and cast an approval vote to the one or several answers that really helped you.
- If you are posting source code with your question, place it inside <pre></pre> tags. We advise you also check the "Encode "<" (and other HTML) characters when pasting" checkbox before pasting anything inside the PRE block, and make sure "Use HTML in this post" check box is checked.
- Be courteous and DON'T SHOUT. Everyone here helps because they enjoy helping others, not because it's their job.
- Please do not post links to your question into an unrelated forum such as the lounge. It will be deleted. Likewise, do not post the same question in more than one forum.
- Do not be abusive, offensive, inappropriate or harass anyone on the boards. Doing so will get you kicked off and banned. Play nice.
- If you have a school or university assignment, assume that your teacher or lecturer is also reading these forums.
- No advertising or soliciting.
- We reserve the right to move your posts to a more appropriate forum or to delete anything deemed inappropriate or illegal.
cheers,
Chris Maunder
The Code Project Co-founder
Microsoft C++ MVP
|
|
|
|
|
I am creating a File Picker control, which will have a caption, a textbox, and a button with an image on it. Pretty straightforward. The control will live inside a controls project I have.
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:Marois.Framework.WPF.Controls">
<pre>
<SolidColorBrush x:Key="disabledBackgroundBrush" Color="Gray"/>
<Style TargetType="{x:Type local:MaroisFilePicker}">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate>
<Border x:Name="border"
Background="{TemplateBinding Background}"
BorderBrush="{TemplateBinding BorderBrush}"
BorderThickness="{TemplateBinding BorderThickness}"
CornerRadius="{TemplateBinding BorderThickness}">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="Auto"/>
</Grid.ColumnDefinitions>
<TextBlock Text="{Binding Caption}"
x:Name="caption"
Margin="2"/>
<TextBox Grid.Column="1"
x:Name="textbox"
Text="{Binding File}"/>
<Button Grid.Column="2"
x:Name="button"
Command="{Binding SelectedFileCommand}"/>
</Grid>
</Border>
<ControlTemplate.Triggers>
<Trigger Property="IsEnabled" Value="False">
<Setter TargetName="button" Property="Background" Value="{StaticResource disabledBackgroundBrush}" />
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
If you notice, I have defined a background brush for the textbox disabled state.
So here's the question. All of this lives in my Marois.Framework.WPF.Controls library. When I use this in another app, how do I then define different colors for the controls? Do I need all of this xaml in my app? Or do I somehow reference each part of my control in a style?
In theory, theory and practice are the same. But in practice, they never are.”
If it's not broken, fix it until it is.
Everything makes sense in someone's mind.
|
|
|
|
|
I pass anything that needs custom ("team") colors, a "custom colors" (team) object at "load" time; with "primary" and "secondary" colors and FG, BG colors, that are bound to at run time. The other option is to use "dynamic" resource references; where you play with the resource (brush) that is referenced.
"Before entering on an understanding, I have meditated for a long time, and have foreseen what might happen. It is not genius which reveals to me suddenly, secretly, what I have to say or to do in a circumstance unexpected by other people; it is reflection, it is meditation." - Napoleon I
|
|
|
|
|
I don't understand that at all. Please explain
In theory, theory and practice are the same. But in practice, they never are.”
If it's not broken, fix it until it is.
Everything makes sense in someone's mind.
|
|
|
|
|
It's probably not "MVVM".
"Before entering on an understanding, I have meditated for a long time, and have foreseen what might happen. It is not genius which reveals to me suddenly, secretly, what I have to say or to do in a circumstance unexpected by other people; it is reflection, it is meditation." - Napoleon I
|
|
|
|
|
Huh? That's even momre confusing
In theory, theory and practice are the same. But in practice, they never are.”
If it's not broken, fix it until it is.
Everything makes sense in someone's mind.
|
|
|
|
|
I'm trying to create a ValueConverter in .Net Core 6, except I can't seem to find the System.Windows.Data namespace, where IValueConveter lives.
What am I missing??
In theory, theory and practice are the same. But in practice, they never are.”
If it's not broken, fix it until it is.
Everything makes sense in someone's mind.
|
|
|
|
|
|
Hi everybody,
I want to make an overlay above an app or capturing this app into my window. I think i will use an opengl library i thougth to work with
glfw but the feature that allow mouse passtrough is for the 3.4 version, and current is 3.3.8.
The best way for me were to run the window i want directly inside my own window, and control it for fullscreen and other things. I'm not habit with linux, i know on w10 a lot of possibilities were removed for security reason.
My work is on ArchLinux to be more accurate, i use lxde but if possible i prefer to avoid a "desktop environment"...
Thx !
|
|
|
|
|
I'm still trying to get my Navigation Control. The repo is here[^].
Thanks to @RichardDeeming for all your help so far. I wouldn't have made it this far without your help.
So the Navigataion Container contains one or more Navigation Panes. When a pane is expanded, I want its loading to begin after it is expanded. The pane should expand, then the user sees the circular progress indicator while the list is loading. Then, when the results are returned, the circular progress indicator should go away and the results displayed.
If you run the app now, and expand a section, you'll see that it doesn't expand until it's after it's done loading.
I could use another pair of eyes on this.
In theory, theory and practice are the same. But in practice, they never are.”
If it's not broken, fix it until it is.
Everything makes sense in someone's mind.
|
|
|
|
|
I have created a progress unit control that show a progress in my WPF application and it looks like this:
https://pasteboard.co/peNn9PiguyNC.png
The way I have done this is adding a ListView in my main application view that has a higher ZIndex than the other controls. This essentially overlays all controls, but does not react hit tests and is not visible.
<ListView x:Name="ProgressListView" Grid.Row="1" Grid.RowSpan="2" ItemsSource="{Binding ProgressCollection}" Background="Transparent" Panel.ZIndex="10" IsHitTestVisible="False">
</ListView>
I have most of the WPF code here, but if you need it, I can post it
This works as you can see from the picture. If you look at the picture, there is a close image which is implemented this way:
<Button Grid.Row="0" Grid.Column="1"
Content="{wpf:MaterialIconExt Kind=WindowClose}"
Command="{Binding CloseProgressCommand}"
Style="{StaticResource ProgressButtonStyle}" />
I would like to be able to click this button to close any progress unit, in case it blocks the users view of any controls beneath it. With my current implementation this is not possible as my ListView currently is marked with IsHitTestVisible="False" . That means all controls under it also ignores the hit test, even if I set the buttons IsHitTestVisible to true. That means the button cannot be clicked by the mouse.
How can I make the button work on my progress unit and still have them floating?
So far:
- I have experimented with overriding the hittest of the listview, so I can ignore hittest in code but allow the button to be pressed. This did not work, but I am still looking into this.
- I have tried fiddling with the ZIndex on the Button, but if the listview ZIndex is lower that the rest, then buttons inside it will of cause also be behind it, no matter the buttons ZIndex. Its a part of the ListView.
- I have also looked into the Adorner layer. I find that this could probably work, but it will require a complete rewrite of the logic and as I understand it is not really what it is meant for and will be very complicated.
Any suggestions is very welcome. I am 99% done, I just need the last little piece of the puzzle.
Solution/Workaround
So browsing some more and looking a bit into the links in the replies, I came up with a solution. I found it while browsing but to be honest i forgot where from. Anyway, the first thing i did was taking a part of @Gerry Schmitz advice and remove the z indexs. Then wil browsing @Richards supplied links for the n'th time i came a cross the workaround/solution.
I added a canvas as the first item and moved listview control in there. The canvas was then set to align content to the bottom and then i anchored the listview to the bottom of the canvas. Code looks like this:
<Canvas Grid.Row="1" Grid.RowSpan="2" VerticalAlignment="Bottom">
<ListView x:Name="ProgressListView" ItemsSource="{Binding ProgressCollection}" Background="Transparent" Canvas.Bottom="0" BorderThickness="0">
</ListView>
</Canvas>
This produces some what the result i was expecting. The progress controls is now fully responsive as I am no longer disabling the hittest. And the controls underneath the canvas is responding to mouse events. The reason this works is that the listview control is almost hidden when no progresses are shown. I tiny fraction of the ui in the corner is where the listview is. I could probably enable and disable the hittest in those conditions, but for now i think it is fine.
The reason i am calling this a work around is that when progresses are shown, ei more that 1, the space between the progress controls is not really a space and the mouse event does not sip through to the underlying controls. But we are also talking about 3-4 pixels in width, so only if a user is trying to click between something that is blocking for 5 seconds, then this becomes a problem. I think this will work for now. I still have some styling to do, but the close button now works as expected.
modified 11-Aug-23 4:01am.
|
|
|
|
|
|
I edited my question. For the original question, you are correct. I can't. I found that out and also found the same stackoverflow link you have posted. So my revised question, is now: How can I make the button work on my progress unit and still have them floating?
|
|
|
|
|
You don't need to change the zorder to put it "on top"; you just span the whole grid and then position it the way you want and add it to the (XAML) visual tree last. Or put a canvas behind it for abolute positioning. The button can be placed anywhere relative to the progress "widget" using the same priciples. As for "hit testable", you can "swallow" clicks anytime it simpifies things. (e.Handled = true or false).
(If you can "close" the widget, it begs the question: how do you open it. Maybe the button should be on a top or side "command bar": an enable / disable toggle).
"Before entering on an understanding, I have meditated for a long time, and have foreseen what might happen. It is not genius which reveals to me suddenly, secretly, what I have to say or to do in a circumstance unexpected by other people; it is reflection, it is meditation." - Napoleon I
|
|
|
|
|
I'm working on an app that has two repository projects.
The first is part of my framework and is called ApplicationSecurity. It has Users, Rights, Encryption, etc. It's designed to be generic and used in any app. It expects an instance of an EF DBContext to be passed into the CTOR
The second repo project is for my app itself. Its tables are app specific. The DBContext resides in this project
So, I build the DBContext in this second project, and used it in both.
In my App.cs CTOR I have:
public App()
{
AppHost = Host.CreateDefaultBuilder()
.ConfigureServices((hostContext, services) =>
{
services.AddSingleton<IEventAggregator, EventAggregator>();
services.AddSingleton<IApplicationSecurity, ApplicationSecurity>();
services.AddSingleton<MainWindowViewModel>();
services.AddSingleton<MainWindowView>();
services.AddSingleton<LoginViewModel>();
services.AddSingleton<LoginView>();
})
.Build();
}
[ ] How do I include my DBContext here?
[ ] My ApplicationSecurity class needs an instance of the DBContext class. How can I pass a reference to a DBContext into the ApplicationSecurity CTOR?
In theory, theory and practice are the same. But in practice, they never are.”
If it's not broken, fix it until it is.
Everything makes sense in someone's mind.
|
|
|
|
|
|
OK, so I now have
AppHost = Host.CreateDefaultBuilder()
.ConfigureServices((hostContext, services) =>
{
services.AddDbContext<MooseDBContext>(options =>
{
options.UseSqlServer(_connString);
});
services.AddSingleton<IEventAggregator, EventAggregator>();
services.AddSingleton<IApplicationSecurity, ApplicationSecurity>();
services.AddSingleton<MainWindowViewModel>();
services.AddSingleton<MainWindowView>();
services.AddSingleton<LoginViewModel>();
services.AddSingleton<LoginView>();
})
.Build();
}
But the ApplicationSecurity class needs an instance of MyDbContext. How do I pass that in?
In theory, theory and practice are the same. But in practice, they never are.”
If it's not broken, fix it until it is.
Everything makes sense in someone's mind.
modified 25-Jul-23 19:13pm.
|
|
|
|
|
Add it as a constructor parameter.
Or are you saying that the ApplicationSecurity is defined in an assembly which doesn't have a reference to the assembly where the MooseDBContext is defined?
If that's the case, then you probably want the context to implement an interface:
public interface IApplicationSecurityContext
{
DbSet<YourEntityType> YourEntityTypes { get; }
}
public class ApplicationSecurity : IApplicationSecurity
{
public ApplicationSecurity(IApplicationSecurityContext context)
{
ArgumentNullException.ThrowIfNull(context);
Context = context;
}
private IApplicationSecurityContext Context { get; }
...
}
public class MooseDBContext : DbContext, IApplicationSecurityContext
{
...
} Then register the interfaces as services:
services.AddDbContext<MooseDBContext>(options =>
{
options.UseSqlServer(_connString);
});
services.AddScoped<IApplicationSecurityContext>(sp => sp.GetRequiredService<MooseDBContext>());
You could even create a utility method to automatically register all interfaces implemented by your context:
public static IServiceCollection AddContextInterfaces<TContext>(this IServiceCollection services) where TContext : DbContext
{
ArgumentNullException.ThrowIfNull(services);
foreach (Type t in typeof(TContext).GetInterfaces().Except(typeof(DbContext).GetInterfaces()))
{
services.AddScoped(t, sp => sp.GetRequiredService<TContext>());
}
return services;
}
...
services.AddDbContext<MooseDBContext>(options =>
{
options.UseSqlServer(_connString);
});
services.AddContextInterfaces<MooseDBContext>();
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
 Thanks, that seems to work fine.
My class now looks like this:
using Marois.Framework.Core.AppSecurity.Repository;
using Marois.Framework.Core.Crypto;
using Marois.Framework.Core.Shared;
using Microsoft.EntityFrameworkCore;
namespace Marois.Framework.Core.AppSecurity.Service
{
public class ApplicationSecurity : IApplicationSecurity
{
#region Private Fields
private IApplicationSecurityContext _context { get; }
#endregion
#region CTOR
public ApplicationSecurity(IApplicationSecurityContext context)
{
ArgumentNullException.ThrowIfNull(nameof(context));
_context = context;
}
#endregion
#region Public Methods
public Task<UserEntity> LoginAsync(CredentialsEntity credentials)
{
UserEntity? results = null;
ArgumentNullException.ThrowIfNull(nameof(credentials));
var t = Task.Run(() =>
{
var userRepo = new AppSecurityRepository<UserEntity>((DbContext)_context);
var user = userRepo.Find(x => x.UserName == credentials.UserName);
if (Cryptography.VerifyHash(credentials.Password, user.Password, user.Hash))
{
results = user;
}
return results;
});
return t;
}
#endregion
}
}
In the Login method, would you create an instance of the repo, or create it in the CTOR and persist it?
In theory, theory and practice are the same. But in practice, they never are.”
If it's not broken, fix it until it is.
Everything makes sense in someone's mind.
|
|
|
|
|
It's a dependency, so I'd be inclined to inject the repo rather than the context.
NB: Entity Framework supports asynchronous database queries, so it would be better to offer a FindAsync method on the repo, and get rid of the Task.Run call.
public class ApplicationSecurity : IApplicationSecurity
{
private AppSecurityRepository<UserEntity> _userRepo { get; }
public ApplicationSecurity(AppSecurityRepository<UserEntity> userRepo)
{
ArgumentNullException.ThrowIfNull(nameof(userRepo));
_userRepo = userRepo;
}
public async Task<UserEntity> LoginAsync(CredentialsEntity credentials)
{
var user = await _userRepo.FindAsync(x => x.UserName == credentials.UserName);
if (user is null) return null;
return Cryptography.VerifyHash(credentials.Password, user.Password, user.Hash) ? user : null;
}
} NB2: Why does your user entity have both a Password and a Hash property? I'd expect to see a "protected password" property, and possibly a "salt" property, depending on whether the salt is stored as a separate column or combined with the password hash.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Is there any way to specify a text value when either all items or no items are checked?
In my case I'm using the CheckcComboBox in a report arguments window, so selecting none is the same as all. What I want is to show the word 'All' by default. If any items are selected, then I'd like it to work as it does and show a comma delimited list of checked items.
I have IsSelectAllActive = true in the XAML. I've also tried setting the Text property in the COllectionChanged event. Neither worked.
In theory, theory and practice are the same. But in practice, they never are.”
If it's not broken, fix it until it is.
Everything makes sense in someone's mind.
modified 21-Jun-23 0:33am.
|
|
|
|
|
There's nothing obvious in the (rather limited) documentation[^]; you might need to raise an issue with them[^].
Or, if you've paid for the "plus" edition, use their "priority support" system.
NB: The "free" edition no longer supports commercial use[^]. If you're using it in anything other than a personal or internal-use product, they expect you to pay for it. However, there are a few forks from before the license change which are still properly "free".
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Wonderful. Thanks
In theory, theory and practice are the same. But in practice, they never are.”
If it's not broken, fix it until it is.
Everything makes sense in someone's mind.
|
|
|
|
|
I need to load a large set of images and let the user pick from them. The user will select a folder, and the list should load. A view like this[^] is what I'd like it to look like.
The user should be able to filter the types of images to load. Preferable, I'd like to be able to have tabs for each folder so they can load multiple folders at once.
I'm not sure of the right container to use for this. Would a VirtualizingWrapPanel work for this?
Also, what's the right way to load the list? When the user selects the folder, I'd like it to start loading right away. Getting a list of file names is easy, but then I would probably need some kind of model class to bind to the list.
I'd like to hear what you guys think.
Thanks
In theory, theory and practice are the same. But in practice, they never are.”
If it's not broken, fix it until it is.
Everything makes sense in someone's mind.
|
|
|
|
|