Diskusia – WPF Programátorská kaklulačka - Design a CodeBehind
SpäťUpozorňujeme, že diskusie pod našimi online kurzami sú nemoderované a primárne slúžia na získavanie spätnej väzby pre budúce vylepšenie kurzov. Pre študentov našich rekvalifikačných kurzov ponúkame možnosť priameho kontaktu s lektormi a študijným referentom pre osobné konzultácie a podporu v rámci ich štúdia. Toto je exkluzívna služba, ktorá zaisťuje kvalitnú a cielenú pomoc v prípade akýchkoľvek otázok alebo projektov.


ostrozan:23.5.2018 18:54
V tom případě ti nepomůžu - zkus možná založit vlákno na toto téma, třeba se s tím problémem někdo setkal i v jiných aplikacích.
Možná ještě sem dej (nebo pošli na PM) tvůj kompletni xaml kód - zkusím to u sebe
<Window x:Class="DecHexBinCalculator.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:DecHexBinCalculator"
mc:Ignorable="d"
Title="DecHexBinCalculator" Height="160" WindowStyle="None" Background="Black" Foreground="#ffd0d0d0" FontSize="11" Topmost="True" WindowStartupLocation="CenterScreen" KeyDown="Window_KeyDown" MouseLeftButtonDown="Window_MouseLeftButtonDown">
<Grid Margin="5">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="Auto"/>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
<TextBlock Text="DEC"/>
<TextBlock Text="HEX" Grid.Column="1"/>
<TextBlock Text="BIN" Grid.Column="2"/>
<TextBox Grid.Row="1" Grid.Column="0" MinWidth="30" Text="0" Background="#ff3f3f3f" Foreground="#ffd0d0d0" TextAlignment="Right" Margin="5,0" TabIndex="0" TextChanged="TextBox_TextChanged" PreviewTextInput="DecTbx_PreviewTextInput"/>
<TextBox Grid.Row="1" Grid.Column="1" MinWidth="30" Text="0" Background="#ff3f3f3f" Foreground="#ffd0d0d0" TextAlignment="Right" Margin="5,0" TabIndex="2" TextChanged="TextBox_TextChanged" PreviewTextInput="HexTbx_PreviewTextInput"/>
<TextBox Grid.Row="1" Grid.Column="2" MinWidth="30" Text="0" Background="#ff3f3f3f" Foreground="#ffd0d0d0" TextAlignment="Right" Margin="5,0" TabIndex="4" TextChanged="TextBox_TextChanged" PreviewTextInput="BinTbx_PreviewTextInput"/>
<StackPanel Grid.Row="2" Grid.ColumnSpan="3" Margin="0,5" Orientation="Horizontal" HorizontalAlignment="Center">
<ComboBox Margin="10,0" Background="#ff3f3f3f" Foreground="#d0d0d0" HorizontalAlignment="Center" SelectedIndex="0">
<ComboBoxItem Content="+"/>
<ComboBoxItem Content="-"/>
<ComboBoxItem Content="*"/>
<ComboBoxItem Content="/"/>
<ComboBoxItem Content="^"/>
<ComboBoxItem Content="√"/>
<ComboBoxItem Content="%"/>
<ComboBoxItem Content="&"/>
<ComboBoxItem Content="|"/>
<ComboBoxItem Content="~"/>
<ComboBoxItem Content="<<"/>
<ComboBoxItem Content=">>"/>
</ComboBox>
<ComboBox Margin="10,0" Background="#ff3f3f3f" Foreground="#d0d0d0" HorizontalAlignment="Center" SelectedIndex="0">
<ComboBoxItem Content="Byte"/>
<ComboBoxItem Content="SByte"/>
<ComboBoxItem Content="Ushort"/>
<ComboBoxItem Content="Short"/>
<ComboBoxItem Content="UInt"/>
<ComboBoxItem Content="Int"/>
<ComboBoxItem Content="ULong"/>
<ComboBoxItem Content="Long"/>
</ComboBox>
</StackPanel>
<TextBox Grid.Row="3" Grid.Column="0" MinWidth="30" Text="0" Background="#ff3f3f3f" Foreground="#ffd0d0d0" TextAlignment="Right" Margin="5,0" TabIndex="1" TextChanged="TextBox_TextChanged" PreviewTextInput="DecTbx_PreviewTextInput"/>
<TextBox Grid.Row="3" Grid.Column="1" MinWidth="30" Text="0" Background="#ff3f3f3f" Foreground="#ffd0d0d0" TextAlignment="Right" Margin="5,0" TabIndex="3" TextChanged="TextBox_TextChanged" PreviewTextInput="HexTbx_PreviewTextInput"/>
<TextBox Grid.Row="3" Grid.Column="2" MinWidth="30" Text="0" Background="#ff3f3f3f" Foreground="#ffd0d0d0" TextAlignment="Right" Margin="5,0" TabIndex="5" TextChanged="TextBox_TextChanged" PreviewTextInput="BinTbx_PreviewTextInput"/>
<Rectangle Fill="#4f4f4f" Margin="5" Grid.Row="4" Grid.ColumnSpan="3" Height="5"/>
<TextBox Grid.Row="5" Grid.Column="0" MinWidth="30" Text="0" Background="#ff202020" Foreground="#ffd0d0d0" TextAlignment="Right" Margin="5,0" Focusable="False"/>
<TextBox Grid.Row="5" Grid.Column="1" MinWidth="30" Text="0" Background="#ff202020" Foreground="#ffd0d0d0" TextAlignment="Right" Margin="5,0" Focusable="False"/>
<TextBox Grid.Row="5" Grid.Column="2" MinWidth="30" Text="0" Background="#ff202020" Foreground="#ffd0d0d0" TextAlignment="Right" Margin="5,0" Focusable="False"/>
<Button Name="MinimizeButton" Content="____" Grid.Row="6" Height="20" Width="20" Margin="0,5" Click="MinimizeButton_Click"/>
<Button Name="HelpButton" Content="?" Grid.Row="6" Grid.Column="1" Height="20" Width="20" Margin="0,5" Click="HelpButton_Click"/>
<Button Name="CloseButton" Content="X" Grid.Row="6" Grid.Column="2" Height="20" Width="20" Margin="0,5" Click="CloseButton_Click"/>
</Grid>
</Window>
A co myslíš tím PM? Sorry, vážně moc neovládám zkratky.
namespace DecHexBinCalculator {
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window {
public MainWindow() {
InitializeComponent();
}
private void TextBox_TextChanged(object sender,TextChangedEventArgs e) {
TextBox tb = sender as TextBox;
string s = tb.Text;
tb.CaretIndex = tb.Text.Length;
if (tb.IsFocused) {
if (s != "") {
try { Prevody.Prevod(s, (byte)tb.TabIndex); } catch (Exception ex) { MessageBox.Show(ex.Message); }
}
/*Vypocty.Result = 0;
ShowResult();
ViewDec();
ViewHex();
ViewBin();
} else {
if (tb.TabIndex % 2 == 0) ClearA();
else ClearB();
ClearRes();*/
}
}
private void DecTbx_PreviewTextInput(object sender, TextCompositionEventArgs e) {
if (!char.IsDigit(e.Text, 0)) e.Handled = true;
}
private void HexTbx_PreviewTextInput(object sender, TextCompositionEventArgs e) {
string hexValue = "0123456789ABCDEFabcdef";
if (!hexValue.Contains(e.Text)) e.Handled = true;
}
private void BinTbx_PreviewTextInput(object sender, TextCompositionEventArgs e) {
string binValue = "01";
if (!binValue.Contains(e.Text)) e.Handled = true;
}
private void Window_KeyDown(object sender, KeyEventArgs e) {
/*if (e.Key == Key.Enter) {
try {
Vypocty.Vypocet();
ShowResult();
} catch (Exception ex) {
MessageBox.Show(ex.Message);
}
} else if (e.Key == Key.Escape) {
ClearAll();
}*/
}
private void Window_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
{
while (Mouse.LeftButton == MouseButtonState.Pressed) DragMove();
}
private void MinimizeButton_Click(object sender, RoutedEventArgs e) {
this.WindowState = WindowState.Minimized;
}
private void HelpButton_Click(object sender, RoutedEventArgs e) {
//WindowHelp.Show();
}
private void CloseButton_Click(object sender, RoutedEventArgs e) {
this.Close();
}
}
}
Ještě to není dodělané, ale to vidíš sám. A mohl bys mi ještě vysvětlit ty operátory od &?
ostrozan:24.5.2018 15:00
Takže - problém se šířkou okna vyřešíš nastavením vlastnosti
SizeToContent na Width
a k té další otázce:
(nejen) vXAMLu jsou některé znaky zakázané používat ve své podobě
(např. <,>,&) a
když je chceš použít, tak je musíš zadat speciálním způsobem - tzv odescapovat
Neaktivní uživatel:24.5.2018 15:09
- Díky.
- Ano, tohle vím, ptal jsem se na funkci těch operátorů v C#. Tenhle řádek
List<string> operatory = new List<string>() { "+", "-", "x", "/", "%", "&", "|", "^", "~", "<<", ">>" };
co máš v kódu nahoře, konkrétně tuto část
{ "&", "|", "^", "~", "<<", ">>" };
tak, jak ji máš použitou ve 2. části tutoriálu.
Jo ták
to jsou logické operátory a operátory pro bitové operace (and,or,xor,negace,posun vlevo,posun vpravo)
Zobrazené 9 správy z 29.