我有一个WrapPanel和按钮以编程方式创建并添加为WrapPanel的子项.因此,当WrapPanel充满按钮(子)时,我想显示垂直滚动条,以便能够连续添加更多按钮.
如果我们需要显示滚动条,我们是否必须携带ScrollViewer?没有ScrollViewer没有办法吗?我想得到的是,因为WrapPanel的尺寸很小,我希望只在需要时显示一个滚动条(就像孩子一样).
我的代码很简单如下(Grid中的WrapPanel和GridControl内的Grid)
非常感谢您的卓越.
更新:我努力在互联网上寻找解决方案甚至好几天.我尝试将WrapPanel放在ScrollViewer中.但是,虽然我将VerticalScroll设置为auto,但即使WrapPanel没有任何子项,也会始终显示垂直滚动条.
此外,当我故意让WrapPanel充满子项(按钮)时,ScrollViewer的垂直滚动条不提供向下滚动可用性.并且WrapPanel底线的按钮显示剪切更多,我无法向下滚动以查看底部按钮以外的按钮.我故意将按钮放在WrapPanel的底线之外.
有或没有,我希望只在需要时显示垂直滚动条(充满孩子).这似乎很容易完成.但它很难使其正常工作.
解决方案:由Henk Holterman先生提供
<DropShadowEffect/>
</Button.Effect>
</Button>
<WrapPanel x:Name="WrapPanelGreen" HorizontalAlignment="Left" Height="180" VerticalAlignment="Top" Width="232" UseLayoutRounding="True" ScrollViewer.CanContentScroll="True" ScrollViewer.VerticalScrollBarVisibility="Auto"/>
</Grid>
</TabItem>
</TabControl>
Run Code Online (Sandbox Code Playgroud)
下面是我的简单代码,它以编程方式创建按钮并添加为WrapPanel的子代.
for (int k = 0; k < Overviews.Length; k++)
{
Button btnoverviewcontent = new Button();
ToolTip tt = new ToolTip();
tt.Content = "Press this button if you want to modify or delete.";
btnoverviewcontent.ToolTip = tt;
btnoverviewcontent.Cursor = Cursors.Hand;
SolidColorBrush mySolidColorBrush = new SolidColorBrush();
mySolidColorBrush.Color = Color.FromArgb(255, 101, 173, 241);
btnoverviewcontent.Background = mySolidColorBrush;
btnoverviewcontent.Effect …Run Code Online (Sandbox Code Playgroud) 我是一个讨厌SQL的谦虚程序员...... :)请帮我解决这个问题.
我有4个表,例如:
Table A:
Id Total
1 100
2 200
3 500
Table B
ExtId Amount
1 10
1 20
1 13
2 12
2 43
3 43
3 22
Table C
ExtId Amount
1 10
1 20
1 13
2 12
2 43
3 43
3 22
Table D
ExtId Amount
1 10
1 20
1 13
2 12
2 43
3 43
3 22
Run Code Online (Sandbox Code Playgroud)
我需要创建一个SELECT,它显示表B,C和D的Amount字段的Id,Total和SUM,就像这样
Id Total AmountB AmountC AmountD
1 100 43 43 43
2 200 …Run Code Online (Sandbox Code Playgroud) aTextBlock在 aButton里面content。
我想要Text的财产TextBlock。请告知我如何解决这个问题。
下面的代码仅返回ct为System.Windows.Controls.TextBlock
string ct = (sender as Button).Content.ToString();
Run Code Online (Sandbox Code Playgroud)
当然,这Content确实Button是TextBlock System.Windows.Controls.TextBlock
我在 stackoverflow 中发现的非常相似的案例,但人们只提供了错误的答案。
我有一个场景,我有两个新对象,其中只有一个必须根据条件初始化.
但我正在使用"using"块语句来初始化一个新对象.
我怎样才能实现它?请参考以下方案.
int a;
string b;
if()//some codition
{
using(MyClass c1 = new MyClass(a))
{
SomeMethod();
}
}
else
{
using(MyClass c1 = new MyClass(b)
{
SomeMethod();
}
}
Run Code Online (Sandbox Code Playgroud)
有没有更好的方法来实现单一条件或任何其他方式来减少代码?因为我在两种情况下都调用相同的方法.
提前致谢.
此致,Anish
更改Datagrid的.DataContext属性(到新源)时,将清除所选项目,但保留滚动条位置.为了避免这种情况,我调用.ScrollIntoView(.Item(0),在更改datacontext之后,向上移动滚动条.但是它会在几分之一秒内显示错误的页面,当我在更改datacontext之前滚动到顶部时,我也有同样的问题.
那么如何更改.DataContext并同时重置滚动条位置呢?
编辑:我应该提到我的XAML看起来像这样:
<DataGrid VirtualizingStackPanel.IsVirtualizing="True" VirtualizingStackPanel.VirtualizationMode="Recycling">
Run Code Online (Sandbox Code Playgroud)
也许虚拟化是原因.
我正在尝试为我的Windows窗体应用程序创建备份和还原功能.
所以,我试图进行数据库恢复.我的代码是这样的:
string cbdfilename = "c:\\Users\\Public\\Public Document";
SqlConnection.ClearAllPools();
SqlConnection con = new SqlConnection("Data Source=(LocalDB)\\v11.0;AttachDbFilename=|DataDirectory|\\BbCon.mdf;Integrated Security=True;Connect Timeout=30;");
string sql;
sql = "Use master;Alter Database BbCon Set Single_User With Rollback Immediate;Restore Database BbCon From Disk = @FILENAME With Replace;Alter Database BbCon Set Multi_User;";
SqlCommand cmd = new SqlCommand(sql, con);
cmd.Parameters.AddWithValue("@FILENAME", cbdfilename);
con.Open();
try
{
cmd.ExecuteNonQuery();
}
catch(Exception ex)
{
MessageBox.Show("Restore DB failed" + ex.ToString());
}
finally
{
con.Close();
con.Dispose();
}
Run Code Online (Sandbox Code Playgroud)
但是当我尝试运行它时,我收到一个错误:
还原db失败System.Data.SqlClient.SqlException(0X80131904):userdoes无权更改数据库BbCon.mdf数据库不存在或者数据库未处于允许访问检查的状态.
有人可以帮我吗?
我有一个类如下,
class Student
{
public string Name {get; set;}
public string Surname {get; set;}
public int Age {get; set;}
public string Address {get; set;}
}
Run Code Online (Sandbox Code Playgroud)
我有一个包含50,000条记录的MySql表.表的结构如下,
ID NAME SURNAME AGE ADDRESS
1 Joe Philip 20 Moscow
2 Misha Johny 25 London
...
Run Code Online (Sandbox Code Playgroud)
我有一个C#代码,
List<Student> students = new List<Student>();
string sql = "SELECT name,surname,age,address FROM Students";
command.CommandText = sql;
MySqlDataReader reader = command.ExecuteReader();
while(reader.Read())
{
Student st = new Student();
st.Name = reader["Name"].ToString();
st.Surname = reader["Surname"].ToString();
st.Age = Convert.ToInt32(reader["Age"].ToString());
st.Address = …Run Code Online (Sandbox Code Playgroud) 我有以下ItemArray:
dt.Rows[0].ItemArray.. //{0,1,2,3,4,5}
Run Code Online (Sandbox Code Playgroud)
标题为:item0,item1,item2等。
到目前为止,要从ItemArray中获取值,我曾经用索引来调用它。
有什么方法可以使用基于列名称的Linq表达式在ItemArray中获取值?
谢谢
我有以下字符串
string a = @"\\server\MainDirectory\SubDirectoryA\SubdirectoryB\SubdirectoryC\Test.jpg";
Run Code Online (Sandbox Code Playgroud)
我正在尝试删除部分字符串,所以最后我想留下
string a = @"\\server\MainDirectory\SubDirectoryA\SubdirectoryB";
Run Code Online (Sandbox Code Playgroud)
所以目前我正在做
string b = a.Remove(a.LastIndexOf('\\'));
string c = b.Remove(b.LastIndexOf('\\'));
Console.WriteLine(c);
Run Code Online (Sandbox Code Playgroud)
这给了我正确的结果.我想知道是否有更好的方法来做到这一点?因为我必须在很少的地方做这件事.
注:该SubdirectoryC长度将是未知的.因为它是由用户输入的数字/字母组成的
我正在使用visual studio,我为C#创建了一个Windows窗体应用程序.我试过这些代码:
//1st
textBox1.Text = "\a";
Thread.Sleep(500);
Run Code Online (Sandbox Code Playgroud)
和
//2nd
Messagebox.Show("\a");
Thread.Sleep(500);
Run Code Online (Sandbox Code Playgroud)
和
//3rd
Console.WriteLine("\a");
Thread.Sleep(500);
Run Code Online (Sandbox Code Playgroud)
但是这些代码都没有从\转义序列中产生任何声音.但是,当我在控制台应用程序上尝试第3组代码时,它可以工作.我应该使用什么代码来允许\转义序列在Windows窗体应用程序中工作并产生声音?
c# ×9
wpf ×3
winforms ×2
ado.net ×1
beep ×1
button ×1
datagrid ×1
datareader ×1
datatable ×1
directory ×1
if-statement ×1
instance ×1
join ×1
linq ×1
list ×1
localdb ×1
mysql ×1
operators ×1
restore ×1
scroll ×1
scrollbar ×1
select ×1
sql ×1
sql-server ×1
string ×1
sum ×1
textblock ×1
wrappanel ×1