|
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'm trying to create a ListBox, with it's ItemTemplate being an expander, which itself has a list in it.
Here's a pic of what I'm trying to accomplish. Pic
I added colors around each item to highlight what's happening.
Here's the XAML
<ListBox Grid.Row="2"
Grid.Column="1"
x:Name="outerList"
Margin="2,2,2,2"
Background="Transparent"
ItemsSource="{Binding RecentItemSections}"
SelectedItem="{Binding SelectedRecentItemSection}"
HorizontalAlignment="Stretch"
BorderBrush="Yellow"
BorderThickness="2">
<ListBox.ItemTemplate>
<DataTemplate>
<Expander IsExpanded="{Binding IsSectionExpanded}"
x:Name="expander"
HorizontalAlignment="Stretch"
BorderBrush="Red"
BorderThickness="2">
<Expander.Header>
<TextBlock Text="{Binding SectionName}"
Foreground="White"
Width="{Binding RelativeSource={RelativeSource Mode=FindAncestor,
AncestorType={x:Type ListBoxItem}}, Path=ActualWidth}"/>
</Expander.Header>
<ListBox ItemsSource="{Binding RecentItems}"
BorderBrush="Green"
BorderThickness="5"
Margin="2,0,20,0">
<ListBox.ItemTemplate>
<DataTemplate>
<Border BorderBrush="MediumAquamarine"
BorderThickness="2">
<StackPanel Orientation="Vertical"
HorizontalAlignment="Stretch">
<TextBlock Text="{Binding ItemName}"
FontSize="12"
Margin="2"/>
<TextBlock Text="{Binding ItemLocation}"
FontSize="10"
Margin="2,0,2,2"/>
</StackPanel>
</Border>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
</Expander>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
As you can see in the pic, the Expander's header is off the right side of the listbox item.
How can I get the expander to fit inside its parent, the ListBox?
If it's not broken, fix it until it is.
Everything makes sense in someone's mind.
Ya can't fix stupid.
|
|
|
|
|
You should know what the maximum header width will be; set the .Width accordingly. (The framework doesn't know beforehand).
"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'd like to load a TabItems's content async.
What would be nice is to see the Tab Item added to the TabControl, then do the async load while a spinning indicator is running.
Something like ContentRendered would do, but I don't see anything like it on the TabItem.
Anyone know of a way to do this?
If it's not broken, fix it until it is.
Everything makes sense in someone's mind.
Ya can't fix stupid.
|
|
|
|
|
When I do this type of thing, I use MVVM and have a state represent the loaded nature; the visibility of the spinner animation is bound to the loaded state.
|
|
|
|
|
Let me clarify my question... I'm not asking about the indicator...
- Tab appears.
- Spinning indicator appears
- Call GetData
- Data is returned
- Tab's content is loaded
- Indicator goes away.
The problem is that I want to show a blank tab first, then start the process of getting the data. But where do you start it from? There doesn't seem to be a ContentRedered or Loaded or Initialized event to kick off the async data call after the tab is visible
If it's not broken, fix it until it is.
Everything makes sense in someone's mind.
Ya can't fix stupid.
|
|
|
|
|
I can't tell whether you are using MVVM or not from your question. If I were doing this, I would adopt a slightly different approach; I would bind the tabs to an ObservableCollection. When I instantiate my new tab and add it to the collection, I would trigger the async load. In other words, I disconnect the state from the visual. I don't need to worry about tracking tab states because this is automatically connected to my ViewModel.
|
|
|
|
|
TabItem inherits from FrameworkElement and therefore has a "Loaded" event.
"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
|
|
|
|
|
When you design a CustomControl or UserControl, how do you fire off a method inside it?
Say for example you create a control that needs to load some data async. So you put the control on a Window and start the window. There's no way to call into the control and call 'Load()'.
You can bind to it, but what would you bind? You could have it listen to an event. Is there some other way?
If it's not broken, fix it until it is.
Everything makes sense in someone's mind.
Ya can't fix stupid.
modified 31-Dec-22 14:45pm.
|
|
|
|
|
You can use async but you may be on a different thread to the UI when trying to update data bound to the UI. You need to marshall to the UI thread or you will get cross-thread exceptions. My previous answer where I point to a series of WPF YT videos will answer this question for you.
Graeme
"I fear not the man who has practiced ten thousand kicks one time, but I fear the man that has practiced one kick ten thousand times!" - Bruce Lee
|
|
|
|
|
Not sure what you mean by this response.
I'm asking how to create a UserControl or CustomControl, place it on a Window, then execute a method on it from a button click on the Window.
If it's not broken, fix it until it is.
Everything makes sense in someone's mind.
Ya can't fix stupid.
|
|
|
|
|
Kevin Marois wrote: I'm asking how to create a UserControl or CustomControl, place it on a Window, then execute a method on it from a button click on the Window.
Okay, that is a lot clearer and easier to understand what you want.
I wrote an article that walks through extending a Control: Flexible WPF ToggleSwitch Lookless Control in C# & VB[^]. UserControls are just like another Window to use.
Graeme
"I fear not the man who has practiced ten thousand kicks one time, but I fear the man that has practiced one kick ten thousand times!" - Bruce Lee
|
|
|
|
|
|
I'm not asking about events. I'm asking how to call the Load method on my UserControl from the Window's ViewModel. The UserControl uis a stand along control. It needs to have Load called to load up the data. The Window's ViewModel doesn't know about the UserControl.
If it's not broken, fix it until it is.
Everything makes sense in someone's mind.
Ya can't fix stupid.
|
|
|
|
|
You give the user control a .Name in the XAML; the .Name is available to the Window's code behind. If you want to access the UC outside of the Window, you need to add a public reference to the UC; e.g. public Type UC => (name of UC in XAML).
In those cases where the UC is a (global) singleton, I (may) give it a public static reference to its instance; the UC can then be accessed by any part of the app in that case.
"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
|
|
|
|
|
There is no code behind. I'm using MVVM
If it's not broken, fix it until it is.
Everything makes sense in someone's mind.
Ya can't fix stupid.
|
|
|
|
|
You could have said that at the outset: "I will only entertain MVVM solutions". Noted.
"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
|
|
|
|
|
Sorry for the confusion. I just asumed that MVVM is the way most folks do things.
So I found out a way to load my control:
public override void OnApplyTemplate()
{
base.OnApplyTemplate();
Load();
}
Not sure if this is the best way, but it works.
Thanks
If it's not broken, fix it until it is.
Everything makes sense in someone's mind.
Ya can't fix stupid.
|
|
|
|
|
I'm having trouble using Path data for an image. I followed the accepted answer here, but I'm still having issues.
<Button Height="50"
Width="50">
<Viewbox Stretch="Uniform">
<Canvas Height="122.88"
Width="122.88">
<Path Fill="Red"
Data="M73.48,15.84A46.87,46.87,0,0,1,84.87,21L91,14.84a7.6,7.6,0,0,1,10.72,0L108,21.15a7.6,7.6,0,0,1,0,10.72l-6.6,6.6a46.6,46.6,0,0,1,4.34,10.93h9.52A7.6,7.6,0,0,1,122.88,57V65.9a7.6,7.6,0,0,1-7.58,7.58h-9.61a46.83,46.83,0,0,1-4.37,10.81L108,91a7.6,7.6,0,0,1,0,10.72L101.73,108A7.61,7.61,0,0,1,91,108l-6.34-6.35a47.22,47.22,0,0,1-11.19,5v8.59a7.6,7.6,0,0,1-7.58,7.58H57a7.6,7.6,0,0,1-7.58-7.58v-7.76a47.39,47.39,0,0,1-12.35-4.68L31.87,108a7.62,7.62,0,0,1-10.72,0l-6.31-6.31a7.61,7.61,0,0,1,0-10.72l4.72-4.72A47.38,47.38,0,0,1,14,73.48H7.58A7.6,7.6,0,0,1,0,65.9V57A7.6,7.6,0,0,1,7.58,49.4h6.35a47.2,47.2,0,0,1,5.51-12.94l-4.6-4.59a7.62,7.62,0,0,1,0-10.72l6.31-6.31a7.6,7.6,0,0,1,10.72,0l5,5A46.6,46.6,0,0,1,49.4,15V7.58A7.6,7.6,0,0,1,57,0H65.9a7.6,7.6,0,0,1,7.58,7.58v8.26ZM59.86,36.68a24.6,24.6,0,1,1-24.6,24.59,24.59,24.59,0,0,1,24.6-24.59Z" />
</Canvas>
</Viewbox>
</Button>
If I change the size of the Canvas, the image skews off to the side.
How can I get the Gear icon to be a fixed size and stay centered regardless of the button or canvas size?
If it's not broken, fix it until it is.
Everything makes sense in someone's mind.
Ya can't fix stupid.
|
|
|
|
|
If you want to "fix the size" of the path figure, set the Width and Height on the Viewbox (otherwise it stretches or shrinks).
You could probably do away with Canvas alltogether in this case (coordinates can operate in "virtual space").
"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
|
|
|
|
|
 OK, so here's what I have now:
<Button Height="25"
Width="75">
<Viewbox Stretch="Uniform"
Height="20"
Width="20">
<Canvas Height="122.88"
Width="122.88">
<Path Fill="Red"
Data="M73.48,15.84A46.87,46.87,0,0,1,84.87,21L91,14.84a7.6,7.6,0,0,1,10.72,0L108,21.15a7.6,7.6,0,0,1,0,10.72l-6.6,6.6a46.6,46.6,0,0,1,4.34,10.93h9.52A7.6,7.6,0,0,1,122.88,57V65.9a7.6,7.6,0,0,1-7.58,7.58h-9.61a46.83,46.83,0,0,1-4.37,10.81L108,91a7.6,7.6,0,0,1,0,10.72L101.73,108A7.61,7.61,0,0,1,91,108l-6.34-6.35a47.22,47.22,0,0,1-11.19,5v8.59a7.6,7.6,0,0,1-7.58,7.58H57a7.6,7.6,0,0,1-7.58-7.58v-7.76a47.39,47.39,0,0,1-12.35-4.68L31.87,108a7.62,7.62,0,0,1-10.72,0l-6.31-6.31a7.61,7.61,0,0,1,0-10.72l4.72-4.72A47.38,47.38,0,0,1,14,73.48H7.58A7.6,7.6,0,0,1,0,65.9V57A7.6,7.6,0,0,1,7.58,49.4h6.35a47.2,47.2,0,0,1,5.51-12.94l-4.6-4.59a7.62,7.62,0,0,1,0-10.72l6.31-6.31a7.6,7.6,0,0,1,10.72,0l5,5A46.6,46.6,0,0,1,49.4,15V7.58A7.6,7.6,0,0,1,57,0H65.9a7.6,7.6,0,0,1,7.58,7.58v8.26ZM59.86,36.68a24.6,24.6,0,1,1-24.6,24.59,24.59,24.59,0,0,1,24.6-24.59Z" />
</Canvas>
</Viewbox>
</Button>
The Gear image now is halfway hidden below.
Here's what it looks like now
If it's not broken, fix it until it is.
Everything makes sense in someone's mind.
Ya can't fix stupid.
|
|
|
|
|
 No, I'm not seeing that. You're either inheriting something; or it's a version thing. I tested it with a new WPF .NET 6.0 project.
<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:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:WpfApp1"
mc:Ignorable="d"
Title="MainWindow"
Height="450"
Width="800">
<Grid>
<Button Height="25"
Width="75">
<pre>
<Viewbox Stretch="Uniform"
Height="20"
Width="20">
<Canvas Height="122.88"
Width="122.88">
<Path Fill="Red"
Data="M73.48,15.84A46.87,46.87,0,0,1,84.87,21L91,14.84a7.6,7.6,0,0,1,10.72,0L108,21.15a7.6,7.6,0,0,1,0,10.72l-6.6,6.6a46.6,46.6,0,0,1,4.34,10.93h9.52A7.6,7.6,0,0,1,122.88,57V65.9a7.6,7.6,0,0,1-7.58,7.58h-9.61a46.83,46.83,0,0,1-4.37,10.81L108,91a7.6,7.6,0,0,1,0,10.72L101.73,108A7.61,7.61,0,0,1,91,108l-6.34-6.35a47.22,47.22,0,0,1-11.19,5v8.59a7.6,7.6,0,0,1-7.58,7.58H57a7.6,7.6,0,0,1-7.58-7.58v-7.76a47.39,47.39,0,0,1-12.35-4.68L31.87,108a7.62,7.62,0,0,1-10.72,0l-6.31-6.31a7.61,7.61,0,0,1,0-10.72l4.72-4.72A47.38,47.38,0,0,1,14,73.48H7.58A7.6,7.6,0,0,1,0,65.9V57A7.6,7.6,0,0,1,7.58,49.4h6.35a47.2,47.2,0,0,1,5.51-12.94l-4.6-4.59a7.62,7.62,0,0,1,0-10.72l6.31-6.31a7.6,7.6,0,0,1,10.72,0l5,5A46.6,46.6,0,0,1,49.4,15V7.58A7.6,7.6,0,0,1,57,0H65.9a7.6,7.6,0,0,1,7.58,7.58v8.26ZM59.86,36.68a24.6,24.6,0,1,1-24.6,24.59,24.59,24.59,0,0,1,24.6-24.59Z" />
</Canvas>
</Viewbox>
</Button>
</Grid>
"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
|
|
|
|
|
In Visual Studio(Community Edition, latest version), when I select an image for the background on a page in WPF, the image file is being copied from the images folder to where the page file is. Looked around and can't find a way to turn this off.
Is there a way to turn this off, and why is Visual Studio doing this?
Thanks
[Tim]
|
|
|
|
|
tbenner1960 wrote: when I select an image for the background on a page in WPF
How did you do this, exactly?
tbenner1960 wrote: Is there a way to turn this off, and why is Visual Studio doing this?
I'm wondering how you got VS to do this because it's not a feature that can be turned on and off, it's not even a feature!, and I can't duplicate the problem on my machine.
|
|
|
|
|