|
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
|
|
|
|
|
Estoy haciendo una App(WPF) en Visual Studio 2022, mi pregunta es la siguiennte: quisiera que las ventanas que abro no aparezcan en el Administrador de Tareas, es una App que inicia con el sistema y al cerrar sesión a apagar la computadora me dice que hay ventanas abiertas, eso es lo que no quiero, si alguien me puede ayudar?, gracias
Translation:
I'm making an App(WPF) in Visual Studio 2022, my question is the following: I would like the windows I open not to appear in the Task Manager, it's an App that starts with the system and when I log out to turn off the computer it tells me that there are open windows, that's what I don't want, if someone can help me?, Thank you
|
|
|
|
|
Nelson1965 wrote: I would like the windows I open not to appear in the Task Manager
The dream of malware authors everywhere!
No, you can't hide your application from the task manager. At least not without writing and installing a "rootkit", which will get your application banned with extreme prejudice.
Nelson1965 wrote: when I log out to turn off the computer it tells me that there are open windows
You don't need to hide your application from the task manager to avoid that. Any normal application will shut down when the user logs out. If you need to do something special when that happens, subscribe to the Application.SessionEnding event[^].
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
I have a SpinningIndicator in a USERCONTROL. It works fine with no problems.
Now, I want to move it to a CUSTOMCONTROL. But it fails to compile on this line:
DoubleAnimation Storyboard.TargetProperty="RenderTransform.Angle"
The error message is
Cannot resolve all property references in the property path 'RenderTransform.Angle'. Verify that applicable objects support the properties.
Here's my XAML
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:ctrl="clr-namespace:Marois.Controls.ProgressIndicators">
<pre>
<Style TargetType="{x:Type ctrl:SpinningIndicator}">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type ctrl:SpinningIndicator}">
<Border Background="{Binding Background, RelativeSource={RelativeSource TemplatedParent}}"
BorderBrush="{Binding BorderBrush, RelativeSource={RelativeSource TemplatedParent}}"
BorderThickness="{Binding BorderThickness, RelativeSource={RelativeSource TemplatedParent}}"
Margin="{Binding Margin, RelativeSource={RelativeSource TemplatedParent}}"
Padding="{Binding Padding, RelativeSource={RelativeSource TemplatedParent}}">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<Canvas Grid.Row="0"
Name="Canvas1"<br />
RenderTransformOrigin="0.5,0.5"<br />
HorizontalAlignment="Center"<br />
VerticalAlignment="Center"
Width="120"
Height="120">
<Canvas.RenderTransform>
<RotateTransform Angle="0" />
</Canvas.RenderTransform>
<Canvas.Style>
<Style TargetType="Canvas">
<Style.Triggers>
<Trigger Property="IsVisible" Value="True">
<Trigger.EnterActions>
<BeginStoryboard Name="Storyboard_Rotate">
<Storyboard RepeatBehavior="Forever">
<DoubleAnimation Storyboard.TargetProperty="RenderTransform.Angle"
From="0"
To="360"
Duration="0:0:3"/>
</Storyboard>
</BeginStoryboard>
</Trigger.EnterActions>
<Trigger.ExitActions>
<StopStoryboard BeginStoryboardName="Storyboard_Rotate" />
</Trigger.ExitActions>
</Trigger>
</Style.Triggers>
</Style>
</Canvas.Style>
<Ellipse Width="20" Height="20" Stretch="Fill" Fill="{Binding IndicatorBrush}" Opacity="1.0" Canvas.Left="50" Canvas.Top="0" />
<Ellipse Width="20" Height="20" Stretch="Fill" Fill="{Binding IndicatorBrush}" Opacity="0.9" Canvas.Left="20.6107373853764" Canvas.Top="9.54915028125262" />
<Ellipse Width="20" Height="20" Stretch="Fill" Fill="{Binding IndicatorBrush}" Opacity="0.8" Canvas.Left="2.44717418524233" Canvas.Top="34.5491502812526" />
<Ellipse Width="20" Height="20" Stretch="Fill" Fill="{Binding IndicatorBrush}" Opacity="0.7" Canvas.Left="2.44717418524232" Canvas.Top="65.4508497187474" />
<Ellipse Width="20" Height="20" Stretch="Fill" Fill="{Binding IndicatorBrush}" Opacity="0.6" Canvas.Left="20.6107373853763" Canvas.Top="90.4508497187474" />
<Ellipse Width="20" Height="20" Stretch="Fill" Fill="{Binding IndicatorBrush}" Opacity="0.5" Canvas.Left="50" Canvas.Top="100" />
<Ellipse Width="20" Height="20" Stretch="Fill" Fill="{Binding IndicatorBrush}" Opacity="0.4" Canvas.Left="79.3892626146236" Canvas.Top="90.4508497187474" />
<Ellipse Width="20" Height="20" Stretch="Fill" Fill="{Binding IndicatorBrush}" Opacity="0.3" Canvas.Left="97.5528258147577" Canvas.Top="65.4508497187474" />
<Ellipse Width="20" Height="20" Stretch="Fill" Fill="{Binding IndicatorBrush}" Opacity="0.2" Canvas.Left="97.5528258147577" Canvas.Top="34.5491502812526" />
</Canvas>
</Grid>
</Border>
</ControlTemplate>
</Setter.Value>
</Setter>
</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.
|
|
|
|
|
Try changing the TargetProperty to just "Angle" instead of "RenderTransform.Angle" - no guarantees, but it might work.
".45 ACP - because shooting twice is just silly" - JSOP, 2010 ----- You can never have too much ammo - unless you're swimming, or on fire. - JSOP, 2010 ----- When you pry the gun from my cold dead hands, be careful - the barrel will be very hot. - JSOP, 2013
|
|
|
|
|
I've got some localization code like this:
<TextBlock Grid.Row="2"
Grid.Column="1"
Text="Close"
beh:LocalizationBehavior.LocalizationKey="{x:Static const:LocalizationKeys.DlgCloseButtonCaption}"/>
The behavior calls a static service which looks up the translation. It works fine on first load when the OnValueChanged fires.
But, when the user changes the selected language is there some way to get the behavior to 'refresh', or re-evaluate?
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.
modified 19-Aug-24 18:11pm.
|
|
|
|
|
Do something like this?
InputLanguageManager.SetInputLanguage(myTextBox, CultureInfo.CreateSpecificCulture("fr"));
Looks like you can do the entire window too, by passing this instead of the textbox.
".45 ACP - because shooting twice is just silly" - JSOP, 2010 ----- You can never have too much ammo - unless you're swimming, or on fire. - JSOP, 2010 ----- When you pry the gun from my cold dead hands, be careful - the barrel will be very hot. - JSOP, 2013
modified 12-Sep-24 10:28am.
|
|
|
|
|
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.
|
|
|
|
|
Did that work?
".45 ACP - because shooting twice is just silly" - JSOP, 2010 ----- You can never have too much ammo - unless you're swimming, or on fire. - JSOP, 2010 ----- When you pry the gun from my cold dead hands, be careful - the barrel will be very hot. - JSOP, 2013
|
|
|
|
|
I have a textblock title in very large font, we'll call it titleTextBlock for simplicity. I can't seem to figure out how to bind it to my tabcontrol tabitem textblocks so that when a user clicks on the tabitem it shows what they've clicked on in titleTextBlock. When I try binding to element I can only seem to bind to one tabitem element. Any ideas?
|
|
|
|
|
Hello, in WPF I want to use a combobox powered by Richtextbox (or something allowing me to do the same). Richtextbox contains text and images on the same line. I would like when we click on the comboxbox that we can see each item with the text + images, and when we select an element of the Combobox, it appears as a selected element and appears correctly with the text and the images. Is it possible (I guess yes) in this case, how to do it using the MVVM pattern? THANKS
|
|
|
|
|
I have a flat text file of which here is an example line:
sample 1 : {Image1} blah {image2} blah.
sample 2 : blah {Image1} blah
sample 3 : blah blah
sample 4 : {Image1} blah
(each line may be different)
With Image1 and Image2 which represents the name of the image file in the Images of the project.
|
|
|
|
|
I wanna know isn't save in my computer .If i run my game and score high score and then close my game.When i run it again next time there will remain my high score every time i run.
Plz tell me and thank you.
|
|
|
|
|
|
I have a textbox display that has incoming data from a serial port that I display. After 200 lines of data that has came in I want to remove 20 lines at the beginning. Here is my code:
private void TextBoxADCPDisplay_TextChanged(object sender, TextChangedEventArgs e)
{
TextBoxADCPDisplay.SelectionStart = TextBoxADCPDisplay.Text.Length;
TextBoxADCPDisplay.ScrollToEnd();
if (TextBoxADCPDisplay.LineCount > 200)
{
TextBoxADCPDisplay.Select(0, 20);
TextBoxADCPDisplay.SelectedText = "";
}
}
I get some strange behavior. Where after I hit 200 lines I see multiple lines that are the same where they should be different, but if I manually scroll up a little and scroll back down the lines of data that are coming in display as they should. What am I doing wrong?
|
|
|
|
|
geomeo123 wrote:
TextBoxADCPDisplay.Select(0, 20);
TextBoxADCPDisplay.SelectedText = ""; Well, start with the fact that the code you've written will not remove 20 lines; it will remove 20 characters.
Parameters
start The zero-based character index of the first character in the selection.
length The length of the selection, in characters.
So unless you can guarantee that every line is precisely 1 character long, and that the Select method ignores the line-break characters, your code isn't going to do what you want it to do.
If you want to remove 20 lines, you'll need to call TextBox.GetLineLength[^] for each line you want to remove, and sum up the line lengths to get the number of characters you need to select. NB: You'll need to test whether or not the returned value includes the line-break characters, as that's not clear from the documentation.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
I had this code for my old windows form. At the time I didn't pay much attention to it as I had found it on a forum somewhere and I just copied and pasted. The original problem was in Windows forms. After a certain period of time of taking data in the entire program would crash. The code above resolved it, but moving over to WPF I'm finding a lot of things don't work as they should or even have the same methods. I am liking the fact that WPF is a lot more forgiving on certain things though so all good.
Thanks
|
|
|
|
|
I'm looking at the deault combobox style[^]
I'm not entirely sure how to ask what I'm thinking, so please bear with me...
Is it possible to replace a part of the control? For example, if I wanted to create a custome combobox. I know in the C# file I just subclass it
public class MyComboBox : ComboBox
{
static MyComboBox()
{
DefaultStyleKeyProperty.OverrideMetadata(typeof(MyComboBox),
new FrameworkPropertyMetadata(typeof(MyComboBox)));
}
}
But in the Generic.xaml, I seems like I would need to have ALL the default xaml from the site above - so that it looks & functions like a combobox.
Is there a way for me to provide just a new ContentSite? Can I justy define that in my Generic.xaml and somehow apply that to my combobox?
Ot do I need to copy in all the default XAML?
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 seriously recommend picking up a book on WPF. This kind of stuff is covered in them.
Yes, you can replace just about anything you want in a WPF control. You just have to provide the implementation of what you want to replace, not the entire control or any of the implementation above what you're replacing.
The trick is knowing what in the XAML tree you need to replace, and where in the tree you need to provide it. Say you want to replace the Text property of a TextBox with a set of async priority bindings. You don't need to provide all the other XAML for a TextBox. You just need to specify the bindings:
<TextBox>
<TextBox.Text>
<PriorityBinding>
<Binding Path="SlowProperty" IsAsync="true" />
<Binding Path="MediumProperty" IsAsync="true" />
<Binding Path="FastProperty" />
</PriorityBinding>
</TextBox.Text>
</TextBox>
There isn't a XAML and C# component to a control. XAML is run through a compiler to generate the C# code. They are interchangeable, not complimentary to each other. The C# code for the control can exist entirely without XAML and the control will still work just fine. XAML is just a structured representation of a bunch of C# classes with properties being set.
Can you replace the ContentControl of a ComboBox? Sure. Can you replace the XAML and provide your own render code for the Combo? Again, sure.
Is it appropriate to do this? I have no idea what you're trying to do with the Combo, so I can't say.
It's also possible to build your own control that looks and acts like a Combo, but doesn't use a ComboBox, or is even based on the existing ComboBox, control at all. You can build one using a TextBox and a PopUp control to do weird stuff like a "ComboBox" that drops down and shows a bunch of TreeView controls in it.
modified 15-Jun-24 12:16pm.
|
|
|
|
|
I do WPF for a living. I have the Control Development book. In the part about creating custom controls, ALL the xaml from the template is used in the examples.
I want to create subclass of a combox box. I don't need the XAML for the button or the textbox, or any other part except for the content site. If you go look at the XAML in the link I provided, I want to replace this:
<ContentPresenter x:Name="ContentSite"
IsHitTestVisible="False"
Content="{TemplateBinding SelectionBoxItem}"
ContentTemplate="{TemplateBinding SelectionBoxItemTemplate}"
ContentTemplateSelector="{TemplateBinding ItemTemplateSelector}"
Margin="3,3,23,3"
VerticalAlignment="Stretch"
HorizontalAlignment="Left">
Something like this
public class MyComboBox : ComboBox
{
static MyComboBox()
{
DefaultStyleKeyProperty.OverrideMetadata(typeof(MyComboBox),
new FrameworkPropertyMetadata(typeof(MyComboBox)));
}
}
and
<Style TargetType="{x:Type ctrls:MyComboBox}">
<pre>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="ComboBox">
</ControlTemplate>
</Setter.Value>
</Setter>
If I do this XAML, the ENTIRE template is replaced, so I'd have to recreate the textbox, button, etc.
What I'm asking is, instead of replacing the ENTIRE TEMPLATE, can I somehow replace just a small piece of that template?
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 some code I'm trying to move to my view model. And it appears that my Invoke method does not work in it. I have the following code...
public delegate void SetTextCallBackSMT(string text);
Handing my serial port
string SMTData = SpSMT.ReadExisting();
if (SMTData.Contains("\r"))
{
modeSMT = ModeSMT.readLineSMTData;
}
else
{
Invoke(new SetTextCallBackSMT(SetTextSMTDisplay), SMTData.ToString());
}
And my set text method....
private void SetTextSMTDisplay(string text)
{
this.RichTextBoxSMTDisplay.Text += text;
}
The problem I'm having is that Invoke does not exist in the current context. I've tried adding forms name space. I've tried Dispatcher.Invoke, but I can't get that to work either. Any ideas?
|
|
|
|
|
Most code in the view-model doesn't need to worry about threading issues. The binding to the view will usually take care of that for you.
The only exception I'm aware of is if you're updating a collection from a background thread, where you may need to call the BindingOperations.EnableCollectionSynchronization[^] method to get it to work properly.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
This is extremely helpful to know! Thanks!
|
|
|
|
|
I'm trying to update my program to WPF MVVM with Icommands to make my program look a little better and reduce the amount of event handlers, clutter etc, which I've managed to make workish. Well if I press a button in WPF my message box executes, so that's always good right? But I have some properties in my old windows form load event that I need to move over and I'm not exactly sure how I would implement that. I'm using the serialport io namespace and so I'm loading things like this at form load time:
SP.Handshake = Handshake.None;
SP.DataReceived += new SerialDataReceivedEventHandler(SP_DataReceived);
SP meaning serial port. Do I put the above in my wpf form load event and make these public so that my modelview class can see them? Or is there an alternative? My model view class inherits from my viewbasemodel so it doesn't allow inheriting from another base class. I could move them to my viewbasemodel class, but I'm not sure about that one either. I still have to make them run at form load. I have to say I'm only half understanding the modelview at the moment. The tutorials online aren't clicking just yet. But I have made it workish so that's always good.
|
|
|
|
|