|
That was what I was talking about, they are supported for WPF projects as well.
It is called Configuration Manager, you automatically get the debug config and need to set up a release config. The release config holds only the section that apply to the release with a replace directive and the deployment operation replaces the relevant sections and creates a config file.
Never underestimate the power of human stupidity -
RAH
I'm old. I know stuff - JSOP
|
|
|
|
|
I'm trying to get the AForge VideoSourcePlayer to work in a WPF app. It's a WinForms control hosted in a WindowsFormsHost. I can't get this to work ina WinForms app either, but I'm targeting WPF in the end.
XAML
<Grid>
<pre>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="Auto"/>
</Grid.ColumnDefinitions>
<Button Grid.Row="0"
Grid.Column="0"
x:Name="connectBt"
Height="32"
Width="100"
Margin="10,0,2,0"
Click="ConnectBt_Click"
Content="Connect"/>
<Button Grid.Row="0"
Grid.Column="1"
x:Name="disconnectBt"
Height="32"
Width="100"
Margin="2,10,10,10"
Click="DisconnectBt_Click"
Content="Disconnect"/>
<wfi:WindowsFormsHost Grid.Row="1"
Grid.Column="0"
Grid.ColumnSpan="2">
<aforge:VideoSourcePlayer x:Name="videoSourcePlayer"
Dock="Fill"/>
</wfi:WindowsFormsHost>
Code Behind
public partial class MainWindow : Window
{
#region CTOR
public MainWindow()
{
InitializeComponent();
this.DataContext = this;
videoSourcePlayer.NewFrame += VideoSourcePlayer_NewFrame;
videoSourcePlayer.Height = 320;
videoSourcePlayer.Width = 320;
}
#endregion
#region Private Methods
private void Connect()
{
FilterInfoCollection videoDevices = new FilterInfoCollection(FilterCategory.VideoInputDevice);
if (videoDevices.Count == 0)
{
throw new ApplicationException();
}
var selectdDevice = videoDevices[0].MonikerString;
VideoCaptureDevice videoSource = new VideoCaptureDevice(selectdDevice);
OpenVideoSource(videoSource);
}
private void Disconnect()
{
if (videoSourcePlayer.VideoSource != null)
{
videoSourcePlayer.SignalToStop();
videoSourcePlayer.WaitForStop();
}
}
private void HandleNewFrame(ref Bitmap image)
{
}
private void OpenVideoSource(IVideoSource source)
{
videoSourcePlayer.SignalToStop();
videoSourcePlayer.WaitForStop();
videoSourcePlayer.VideoSource = source;
videoSourcePlayer.Start();
}
#endregion
#region Event Handlers
private void Window_Unloaded(object sender, RoutedEventArgs e)
{
Disconnect();
}
private void ConnectBt_Click(object sender, RoutedEventArgs e)
{
Connect();
}
private void DisconnectBt_Click(object sender, RoutedEventArgs e)
{
Disconnect();
}
private void VideoSourcePlayer_NewFrame(object sender, ref Bitmap image)
{
HandleNewFrame(ref image);
}
#endregion
}
When I run this, the VideoSourcePlayer displays "Connecting..." but i never does. The camera moniker string is "@device:pnp:\\?\usb#vid_046d&pid_082d&mi_00#6&39ab8351&0&0000#{65e8773d-8f56-11d0-a3b9-00a0c9223196}\global". it's a Logitech USB camera.
Anyone have any experience with this?
If it's not broken, fix it until it is.
Everything makes sense in someone's mind.
Ya can't fix stupid.
|
|
|
|
|
Adding background as Transparent for WindowsFormsHost worked for me.
<wfi:windowsformshost x:name="VideoSourceWindowsFormsHost" width="100" height="50" grid.row="2" grid.column="1"
="" background="Transparent">
<controls:videosourceplayer x:name="videoSourcePlayer" width="250" height="250">
|
|
|
|
|
I copied the TextBox template from here into my resources. I just want to study it and see how things work, and the TextBox seems simple enough.
I created a a CustomControl of type TextBox called TextBoxEx. I pasted the style into the Generic.xml in the Themes folder, and it doesn't work.
With this code line of in the CTOR, the Border doesn't show up.
public class TextBoxEx : TextBox
{
static TextBoxEx()
{
DefaultStyleKeyProperty.OverrideMetadata(typeof(TextBoxEx), new FrameworkPropertyMetadata(typeof(TextBoxEx)));
}
}
If I comment the line out, the border appears.
if go into the style and change
<Border.BorderBrush>
<SolidColorBrush Color="{DynamicResource BorderMediumColor}" />
</Border.BorderBrush>
to a StaticResource
<Border.BorderBrush>
<SolidColorBrush Color="{StaticResource BorderMediumColor}" />
</Border.BorderBrush>
Then it works ok.
What's going on here?
If it's not broken, fix it until it is.
Everything makes sense in someone's mind.
Ya can't fix stupid.
|
|
|
|
|
I have this DataGrid with three columns:
<DataGrid>
<DataGrid.Columns>
<DataGridTextColumn Header="Col1" Width="100" />
<DataGridTextColumn Header="Col2" Width="Auto" />
<DataGridTextColumn Header="Col3" Width="100" />
</DataGrid.Columns>
</DataGrid> I would like 'Col3' to always be at the right side of the DataGris regardless how wide the DataGrid is.
Since 'Col1' and 'Col3' has fixed widths, 'Col2' is free to dynamically change width.
Is this possible to "Dock" 'Col3' to the right side of the DataGrid?
I'm looking for a solution simular to a DockPanel:
<DataGrid LastChildFill="true">
<Label Content="Col1" DockPanel.Dock="Left" />
<Label Content="Col3" DockPanel.Dock="Right" />
<Label Content="Col2" />
</DockPanel>
|
|
|
|
|
You mean "visible"? If you define it "on the right", it stays there. If the preceding columns are "too wide", you have to add scroll bars.
It was only in wine that he laid down no limit for himself, but he did not allow himself to be confused by it.
― Confucian Analects: Rules of Confucius about his food
|
|
|
|
|
You can "freeze" one of more columns, but only on the left-hand side:
DataGrid.FrozenColumnCount Property (System.Windows.Controls) | Microsoft Docs[^]
You might be able to make it appear on the right-hand side with a custom template, but it would probably require a lot of work.
If you just want column 2 to fill the remaining space, set its width to * :
<DataGridTextColumn Header="Col2" Width="*" />
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Hum... too bad...
Thanks for the reply anyway!
|
|
|
|
|
I want to create a datagrid with dynamic row and column.
I know how create a datagrid and bind the Itemsource.
How define the dynamic column ?
Perhaps you have a short example.
<DataGrid
x:Name="ListViewFiles"
MaxWidth="2560"
MaxHeight="1600"
AutoGenerateColumns="False"
CanUserAddRows="False"
CanUserSortColumns="True"
CellStyle="{StaticResource Content_DataGrid_Centering}"
DockPanel.Dock="Top"
EnableColumnVirtualization="True"
EnableRowVirtualization="True"
ItemsSource="{Binding Path=CloudInterface.ListViewFile}"
PreviewMouseLeftButtonDown="Drag_PreviewMouseLeftButtonDown"
PreviewMouseMove="ListViewFiles_PreviewMouseMove"
RowHeaderWidth="0"
ScrollViewer.CanContentScroll="True"
ScrollViewer.HorizontalScrollBarVisibility="Auto"
ScrollViewer.VerticalScrollBarVisibility="Auto"
SelectionMode="Single">
<DataGrid.Columns>
<DataGridTextColumn Binding="{Binding ConfigItem.MostRecentConfigFile.Product}">
<DataGridTextColumn.HeaderTemplate>
<DataTemplate>
<DockPanel>
<Label Content="{Binding Lab_Product, Source={StaticResource Resources}}" />
</DockPanel>
</DataTemplate>
</DataGridTextColumn.HeaderTemplate>
<DataGridTextColumn.ElementStyle>
<Style TargetType="{x:Type TextBlock}">
<Setter Property="Margin" Value="5" />
<Setter Property="Padding" Value="5" />
</Style>
</DataGridTextColumn.ElementStyle>
</DataGridTextColumn>
<DataGridTextColumn Binding="{Binding ConfigItem.MostRecentConfigFile.ArchitectureSoftwareVersion}">
<DataGridTextColumn.HeaderTemplate>
<DataTemplate>
<DockPanel>
<Label Content="{Binding Lab_Version, Source={StaticResource Resources}}" />
</DockPanel>
</DataTemplate>
</DataGridTextColumn.HeaderTemplate>
<DataGridTextColumn.ElementStyle>
<Style TargetType="{x:Type TextBlock}">
<Setter Property="Margin" Value="5" />
<Setter Property="Padding" Value="5" />
</Style>
</DataGridTextColumn.ElementStyle>
</DataGridTextColumn>
</DataGrid.Columns>
</DataGrid>
|
|
|
|
|
|
|
I have set up the calculation program for the program, but now the problem is that I want to integrate the two classes together but it still is not compatible so you can help me! Textblock caculator not show Only one class can be implemented! code see here :
https:
https:
sql data :
https://i.stack.imgur.com/pCgiK.png[^]
|
|
|
|
|
Please post proper details of your problem. People here cannot guess what your code is doing.
|
|
|
|
|
Edit your question and post just the relevant code. Don't expect people to follow links to who knows what.
Social Media - A platform that makes it easier for the crazies to find each other.
Everyone is born right handed. Only the strongest overcome it.
Fight for left-handed rights and hand equality.
|
|
|
|
|
I have added a Routed Event to a user control:
public static readonly RoutedEvent ItemChangedEvent =
EventManager.RegisterRoutedEvent("ItemChanged",
RoutingStrategy.Bubble,
typeof(RoutedEventHandler),
typeof(DropDownEntryView));
public event RoutedEventHandler ItemChanged
{
add { AddHandler(ItemChangedEvent, value); }
remove { RemoveHandler(ItemChangedEvent, value); }
}
private void RaiseItemChangedEvent(string newValue, string oldValue)
{
var args = new ItemChangedEventArgs(ItemChangedEvent, newValue, oldValue);
RaiseEvent(args);
}
Here is the ItemChangedEventArgs class:
public class ItemChangedEventArgs : RoutedEventArgs
{
public string NewValue { get; private set; }
public string OldValue { get; private set; }
public ItemChangedEventArgs(RoutedEvent routedEvent, string newValue, string oldValue)
: base(routedEvent)
{
NewValue = newValue;
OldValue = OldValue;
}
}
The XAML
<ctrls:DropDownEntryView Grid.Column="0"
Items="{Binding DataContext.EmailItems,
ElementName=clientsView,
Mode=TwoWay,
UpdateSourceTrigger=PropertyChanged}"
EditBarCaption="Edit Emails..."
ShowEditBar="True"
ItemCategoryKey="email_types"
HorizontalAlignment="Left"
Width="400"
Margin="5">
<pre>
<i:Interaction.Triggers>
<i:EventTrigger EventName="ItemChanged">
<i:InvokeCommandAction Command="{Binding ElementName=clientsView, Path=DataContext.EmailItemChangedCommand}"
CommandParameter="{Binding}"/>
</i:EventTrigger>
</i:Interaction.Triggers>
How do I pass the ItemChangedEventArgs in the XAML?
If it's not broken, fix it until it is.
Everything makes sense in someone's mind.
Ya can't fix stupid.
|
|
|
|
|
I would load a list of user controls and use Property Changed instead. Less code.
It was only in wine that he laid down no limit for himself, but he did not allow himself to be confused by it.
― Confucian Analects: Rules of Confucius about his food
|
|
|
|
|
I'm developing some user controls. I want to be able to publish events and pass custom args
If it's not broken, fix it until it is.
Everything makes sense in someone's mind.
Ya can't fix stupid.
|
|
|
|
|
I add "actions" and "functions" to the controls that are wired at will:
public (static) Action<object, object=""> Hook = (o1, o2) => {};
...Hook = MyAction;
...
Hook( this, arg );
...
void MyAction( object sender, object arg ) { ... }
It was only in wine that he laid down no limit for himself, but he did not allow himself to be confused by it.
― Confucian Analects: Rules of Confucius about his food
|
|
|
|
|
I think I understand this. Can you show me an example of coding it in the usercontrol and how it's wired up in the parent window's XAML?
If it's not broken, fix it until it is.
Everything makes sense in someone's mind.
Ya can't fix stupid.
|
|
|
|
|
|
|
I resolved this using one of the workarounds you linked:
<TextBlock Grid.Row="2"
Grid.Column="0"
Text="Emails"
Margin="5,10,5,5"/>
<ctrls:DropDownEntryView Grid.Row="3"
Grid.Column="0"
Grid.ColumnSpan="2"
ItemCategoryKey="email_types"
HorizontalAlignment="Stretch"
Items="{Binding DataContext.EmailItems, ElementName=clientsView}"
ShowEditBar="True"
EditBarCaption="Edit Emails"
Width="400"
Margin="5">
<pre>
<i:Interaction.Triggers>
<i:EventTrigger EventName="ItemChanged" >
<cls:InvokeDelegateCommandAction Command="{Binding DataContext.EmailItemChangedCommand, ElementName=clientsView}"
CommandParameter="{Binding RelativeSource={RelativeSource Self}, Path=InvokeParameter}" />
</i:EventTrigger>
</i:Interaction.Triggers>
If it's not broken, fix it until it is.
Everything makes sense in someone's mind.
Ya can't fix stupid.
|
|
|
|
|
I have a small program, because I'm new, my program is to bring data from sql sever to textbox via combobox option and use the value shown in that textbox to calculate the + I have made it to the step of putting up the data, now thanks to you to help me with the value calculation in the textbox, thank you for your help.
xaml code :
<Window.Resources>
<local:SimpleMath x:Key="MyFriends"/>
</Window.Resources>
<Grid>
<Label Content="code" HorizontalAlignment="Left" Margin="38,52,0,0"
VerticalAlignment="Top" Width="46" Height="23"/>
<Label Content="pieces" HorizontalAlignment="Left" Margin="38,126,0,0"
VerticalAlignment="Top" Width="46" Height="23"/>
<Label Content="layers" HorizontalAlignment="Left" Margin="38,196,0,0"
VerticalAlignment="Top" Width="46" Height="30"/>
<Label Content="production pieces" HorizontalAlignment="Left"
Margin="0,278,0,0" VerticalAlignment="Top" Width="108" Height="25"/>
<TextBox x:Name="txtcode"
Text="{Binding Txtcode, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
HorizontalAlignment="Left" Height="23" Margin="124,52,0,0"
TextWrapping="Wrap" VerticalAlignment="Top" Width="141"/>
<TextBox x:Name="txtpieces"
Text="{Binding Txtpieces, Mode=TwoWay,UpdateSourceTrigger=PropertyChanged}"
HorizontalAlignment="Left" Height="23"
Margin="124,133,0,0" TextWrapping="Wrap" VerticalAlignment="Top" Width="141"/>
<TextBox x:Name="txtlayers"
Text="{Binding Txtlayers,Mode=TwoWay,UpdateSourceTrigger=PropertyChanged}"
HorizontalAlignment="Left" Height="23"
Margin="124,203,0,0" TextWrapping="Wrap" VerticalAlignment="Top" Width="141"/>
<TextBox x:Name="txtproductionpieces"
Text="{Binding Txtproductionpieces,Mode=TwoWay,UpdateSourceTrigger=PropertyChanged}"
HorizontalAlignment="Left" Height="23" Margin="124,280,0,0"
TextWrapping="Wrap" VerticalAlignment="Top" Width="141"/>
<ComboBox x:Name="comboBox1" ItemsSource="{Binding Source={StaticResource MyFriends}}"
HorizontalAlignment="Left" Margin="418,52,0,0" VerticalAlignment="Top"
Width="319" Height="36" SelectionChanged="ComboBox1_SelectionChanged"/>
<TextBox x:Name="txtseccond"
Text="{Binding Txtseccond,Mode=TwoWay,UpdateSourceTrigger=PropertyChanged}"
HorizontalAlignment="Left" Height="23"
Margin="124,345,0,0" TextWrapping="Wrap" VerticalAlignment="Top" Width="141"/>
<Label Content="seccond" HorizontalAlignment="Left" Margin="38,345,0,0"
VerticalAlignment="Top" Width="46" Height="23"/>
<TextBlock Text="{Binding A, Mode=OneWay,UpdateSourceTrigger=PropertyChanged}"
HorizontalAlignment="Left" Margin="418,133,0,0" TextWrapping="Wrap"
VerticalAlignment="Top" Height="23" Width="248"/>
<TextBox Text="{Binding No1,Mode=OneWay,UpdateSourceTrigger=PropertyChanged}"
HorizontalAlignment="Left" Height="21" Margin="426,210,0,0"
TextWrapping="Wrap" VerticalAlignment="Top" Width="303"/>
</Grid>
</Window>
C# code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.Data.SqlClient;
using System.ComponentModel;
using System.Runtime.CompilerServices;
namespace comboboxapp1
{
///
/// Interaction logic for MainWindow.xaml
///
public partial class MainWindow : Window
{
public SimpleMath Formular { get; set; }
public object SelectedValue { get; private set; }
public MainWindow()
{
Formular = new SimpleMath()
{
Txtcode = 0,
Txtpieces = 0,
Txtlayers = 0,
Txtproductionpieces = 0,
Txtseccond = 0,
};
InitializeComponent();
DataContext = Formular;
Fillcombobox();
}
private void MainWindow_Load(object sender, EventArgs e)
{
}
public void Fillcombobox()
{
SqlConnection con = new SqlConnection("Data Source=LEAN-22\\SQLEXPRESS;Initial
Catalog=LUAT;Integrated Security=True");
string sql = " select * from comboboxnew ";
SqlCommand cmd = new SqlCommand(sql, con);
SqlDataReader myreader;
try
{
con.Open();
myreader = cmd.ExecuteReader();
while (myreader.Read())
{
string sname = myreader.GetInt32(0).ToString();
comboBox1.Items.Add(sname);
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
public class SimpleMath : INotifyPropertyChanged
{
private int no1;
public int No1
{
get { return no1; }
set
{
no1 = value;
OnPropertyChanged("No1");
OnPropertyChanged("A");
}
}
private int txtcode;
public int Txtcode
{
get { return txtcode; }
set
{
txtcode = value;
OnPropertyChanged("Txtcode");
OnPropertyChanged("A");
}
}
private int txtpieces;
public int Txtpieces
{
get { return txtpieces; }
set
{
txtpieces = value;
OnPropertyChanged("Txtcode");
OnPropertyChanged("A");
}
}
private int txtlayers;
public int Txtlayers
{
get { return txtlayers; }
set
{
txtlayers = value;
OnPropertyChanged("Txtlayers");
OnPropertyChanged("A");
}
}
private int txtproductionpieces;
public int Txtproductionpieces
{
get { return txtproductionpieces; }
set
{
txtproductionpieces = value;
OnPropertyChanged("Txtproductionpieces");
OnPropertyChanged("A");
}
}
private int txtseccond;
public int Txtseccond
{
get { return txtseccond; }
set
{
txtseccond = value;
OnPropertyChanged("Txtseccond");
OnPropertyChanged("A");
}
}
public double A => No1;
public event PropertyChangedEventHandler PropertyChanged;
public void OnPropertyChanged([CallerMemberName()] string propertyName = null)
{
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
}
}
private void ComboBox1_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
SqlConnection con = new SqlConnection("Data Source=LEAN-22\\SQLEXPRESS;Initial
Catalog=LUAT;Integrated Security=True");
// string sql = " select * from comboboxnew where code = '" + comboBox1.Text+ "';";
string sql = " select * from comboboxnew where code = '" + comboBox1.SelectedItem +
"';";
//Console.WriteLine(comboBox1.Text);
//MessageBox.Show(comboBox1.Text);
SqlCommand cmd = new SqlCommand(sql, con);
SqlDataReader myreader;
try
{
con.Open();
myreader = cmd.ExecuteReader();
while (myreader.Read())
{
string code = myreader.GetInt32(0).ToString();
string pieces = myreader.GetInt32(1).ToString();
string layers = myreader.GetInt32(2).ToString();
string productionpieces = myreader.GetInt32(3).ToString();
string seccond = myreader.GetInt32(4).ToString();
txtcode.Text = code;
//txtcode.Text =SelectedValue;
txtpieces.Text = pieces;
//txtpieces.Text = "New value";
txtlayers.Text = layers;
//txtlayers.Text = "New value";
txtproductionpieces.Text = productionpieces;
//txtproductionpieces.Text = "New value";
txtseccond.Text = seccond;
//txtseccond.Text = "New value";
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
}
}
|
|
|
|
|
What is the problem, and where does it occur?
|
|
|
|
|
|